想设置接入控制允许证书中节点的js使用这样节点JS CORS模块不设置接入控制允许证书头部
`var cors = require('cors');
var corsOptions = {
origin: true,
'Access-Control-Allow-Origin': 'localhost:1550'
'Access-Control-Allow-Credentials': 'true'
};
app.use(cors(corsOptions));`
这并未”的CORS模块配置全局报头t似乎工作,所以我也为我设置预检响应的路线设置了它。我将它设置这样
`router.options('/login', cors(corsOptions));`
我在Chrome开发者工具检查,我看到Access-Control-Allow-Origin
头设置但不Access-Control-Allow-Credentials
。由于我已在Angular中设置了withCredentials = true
,因此我需要此标题。
为什么Node JS没有设置Access-Control-Allow-Credentials头,但它设置了其他的?
我知道这是因为我
XMLHttpRequest cannot load http://www.localhost:1550/api/v1/auth/login. Response to preflight request doesn't pass access control check: Credentials flag is 'true', but the 'Access-Control-Allow-Credentials' header is ''. It must be 'true' to allow credentials. Origin 'http://127.0.0.1:1550' is therefore not allowed access.
谢谢,我现在意识到,我没有把文档彻底丢弃 –