【发布时间】:2018-01-09 16:00:16
【问题描述】:
我有一个 restify 服务器运行我的 API,我定义 cors 中间件如下:
server.use(restify.acceptParser(server.acceptable));
server.use(restify.queryParser());
server.use(restify.bodyParser({
multiples: true,
mapParams: false
}));
server.pre(restify.CORS())
server.use(restify.fullResponse())
server.use(
function crossOrigin(req,res,next){
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
return next();
});
但我总是收到此错误消息:
跨域请求被阻止:同源策略不允许读取位于https://myroute...的远程资源(原因:CORS 预检通道未成功)。
我做错了什么?
【问题讨论】:
标签: cors middleware restify