我的 Restify 服务器中没有 'Access-Control-Allow-Origin' 错误

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

我在我的 Heroku 服务器中使用 Restify。我收到此错误:

 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.

我的 Restify 配置是:

server
.use(restify.fullResponse())
.use(restify.bodyParser())
.use(restify.queryParser())
.use(restify.CORS({
    origins: ['https://xxx.xxx.com', 'http://xxx.xxx.com']
}));

我的配置中缺少什么?

在某些情况下,您可能需要使用 server.pre 而不是 server.use

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