Search code examples
herokucorsrestifypreflight

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


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?


Solution

  • In some cases, you may need to use server.pre instead of server.use.

    https://github.com/restify/node-restify/issues/573