node.js中的CORS问题失败 [英] CORS issue in node.js failing
本文介绍了node.js中的CORS问题失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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();
});
我使用邮递员,一切正常,但是在测试运行在< a href = http:// localhost:8100 rel = nofollow> http:// localhost:8100 。我用谷歌搜索并设法找到上面的设置标头解决方案,但是现在出现了这个错误:
I use postman everything work fine but I got CORS issue when testing my ionic app which it runs at http://localhost:8100. 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.
有什么想法吗?
推荐答案
尝试使用cors中间件。
Try using the cors middleware.
var cors = require('cors');
app.use(cors());
这篇关于node.js中的CORS问题失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文