【发布时间】:2020-12-06 04:41:56
【问题描述】:
我参加了 Ionic 5 课程,当我做其中一个练习时,我想将用 JS 编写的后端放在 github 和 heroku 中,当在我的应用程序中开始我的身份验证时,它会抛出以下错误:
我的后端是 en node and express:
//allow cross config
server.app.use( cors({ origin: true, credentials: true }) );
server.app.use(function (req, res, next) {
// Website you wish to allow to connect
res.setHeader('Access-Control-Allow-Origin', '*');
// Request methods you wish to allow
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
// Request headers you wish to allow
res.setHeader('Access-Control-Allow-Headers', 'x-token, content-type');
next();
});
我的应用需要登录并为每个用户返回一个令牌,并且此令牌用于其他请愿书的标头中
【问题讨论】:
标签: node.js express ionic-framework cors