No 'Access-Control-Allow-Origin' error in my Restify server - heroku

I am using Restify in my Heroku server. I am getting this error:
XMLHttpRequest cannot load https://xxx.xxx.com/charging. Response to preflight request doesn't pass access control check:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://xxx.xxx.com' is therefore not allowed access.
The response had HTTP status code 405.
My Restify configuration is:
server
.use(restify.fullResponse())
.use(restify.bodyParser())
.use(restify.queryParser())
.use(restify.CORS({
origins: ['https://xxx.xxx.com', 'http://xxx.xxx.com']
}));
What is missing in my configuration?

In some cases, you may need to use server.pre instead of server.use.
https://github.com/restify/node-restify/issues/573

Related

Access to XMLHttpRequest at 'https://storeedgefd.dsx.mp.microsoft.com/v9.0/manifestSearch' from origin 'https://devicemanagement.portal.azure.com

I'm getting this error trying to add Microsoft 'New Store' app function in Intune. I tried getting help from Microsoft, but they were no help.
Using Edge and Chrome , both give the same result. My pc has been rebuilt, I reset Edge & Chrome's browser settings, history and everything I can think off. Still have the same issue.
`Access to XMLHttpRequest at 'https://storeedgefd.dsx.mp.microsoft.com/v9.0/manifestSearch' from origin 'https://devicemanagement.portal.azure.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
/#view/Microsoft_Intune_Apps/AppWizardBlade/appId/00000000-0000-0000-0000-000000000000/appType/WinGetStoreApp:1
Access to XMLHttpRequest at '``https://storeedgefd.dsx.mp.microsoft.com/v9.0/manifestSearch``' from origin '``https://devicemanagement.portal.azure.com``' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Access to XMLHttpRequest at '``https://storeedgefd.dsx.mp.microsoft.com/v9.0/manifestSearch``' from origin '``https://devicemanagement.portal.azure.com``' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
/#view/Microsoft_Intune_Apps/AppWizardBlade/appId/00000000-0000-0000-0000-000000000000/appType/WinGetStoreApp:1
Access to XMLHttpRequest at '``https://storeedgefd.dsx.mp.microsoft.com/v9.0/manifestSearch``' from origin '``https://devicemanagement.portal.azure.com``` ' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. ``
Re-installed PC, Reset Edge and Chrome
Tried on another PC , same result.

Cors Option not constant

I'm having problem with CORS.
My Node.js Server with apollo-server-express(version 3.7)
My problem is CORS is not constant.
My React Project request api server and works well.
But sometimes api server response this error
Access to fetch at 'https://api.example.com/' from origin 'https://example.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
Why same client request sometime response cors error?
Please Help.

aimeos jsonapi request blocked by CORS policy

On local development I am facing following error on ajax request:
Access to XMLHttpRequest at 'http://pmb.local/jsonapi/product' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Need to the following change this this file
Ddont forget to run:
php artisan optimize

CORS Issue on iframe to current Laravel route

I am pulling in an Iframe that has javascript included in it. I have installed the fruitcake cors package and set the config file to be wide open. I also added the "Access-Control-Allow-Origin' header to the xmlhttp request just in case because I am confused on who is actually denying the request. Here is the error I am getting -
Access to XMLHttpRequest at "https://site-that-i-am-posting-to" from origin "https://where-the-iframe-is-sourced-from" has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present of the requested resource.
Figured it out. I needed to add the correct request headers to the xmlhttprequest like this -
xhrapi.setRequestHeader('Origin', 'https://site-posting-from.com');
xhrapi.setRequestHeader('Access-Control-Request-Method', 'POST');
And then it worked. Thanks to anyone that tried to help!

Angular 2 able to post request but not able to read the remote resource

I tried to post a request to my Laravel backend but failed to get the response as the error "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8000/path. (Reason: missing token ‘access-control-allow-origin’ in CORS header ‘Access-Control-Allow-Headers’ from CORS preflight channel)" showed.
I have added Access-Control-Allow-Origin and Access-Control-Allow-Headers in both my client and server. Why does the error still showing?
Remove the client-side code you added to send Access-Control-Allow-Origin in the request.
(Reason: missing token ‘access-control-allow-origin’ in CORS header ‘Access-Control-Allow-Headers’ from CORS preflight channel)" showed.
I have added Access-Control-Allow-Origin and Access-Control-Allow-Headers in both my client and server. Why does the error still showing?
The error is showing because you added an Access-Control-Allow-Origin header to the client-side request. But Access-Control-Allow-Origin is a server response header. So if you send it from the client side in a request you’ll see the kind of error you’re seeing now.
“missing token ‘access-control-allow-origin’ in CORS header ‘Access-Control-Allow-Headers’“ is the browser telling you that your client code is sending an Access-Control-Allow-Origin request header, but the Access-Control-Allow-Headers response header the server has returned doesn’t list "Access-Control-Allow-Origin" as one of the header names it allows in requests.
So because of that, the browser isn’t letting your frontend JavaScript code read the response.

Resources