CORS-node.js

app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header("Access-Control-Allow-Headers", "X-Requested-With,Content-Type,Cache-Control");
if (req.method === 'OPTIONS') {
res.statusCode = 204;
return res.end();
} else {
return next();
}
});

跨域请求前,一般浏览器会试探性发送OPTIONS请求.如果ok 就可以继续请求

理论基础:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS