[英]CORS issue in node.js failing
app.use(function (req, res, next) {
// Website you wish to allow to connect
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:8100');
// Request headers you wish to allow
res.setHeader('Access-Control-Allow-Headers', '*');
// Set to true if you need the website to include cookies in the requests sent
// to the API (e.g. in case you use sessions)
res.setHeader('Access-Control-Allow-Credentials', true);
// Pass to next layer of middleware
next();
});
I use postman everything work fine but I got CORS issue when testing my ionic app which it runs at http://localhost:8100 .我使用邮递员一切正常,但是在测试我在http://localhost:8100 上运行的 ionic 应用程序时遇到了 CORS 问题。 I googled and manage to find above set header solution but now I'm getting this error :
我用谷歌搜索并设法找到上面设置的标题解决方案,但现在我收到此错误:
Request header field owner is not allowed by Access-Control-Allow-Headers in preflight response.
Any thought?任何想法?
Try using the cors middleware.尝试使用 cors 中间件。
var cors = require('cors');
app.use(cors());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.