1

我在我的 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']
}));

我的配置中缺少什么?

4

1 回答 1

1

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

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

于 2016-04-11T21:12:12.330 回答