「Angular: CORS预检响应未成功」

16 浏览
0 Comments

「Angular: CORS预检响应未成功」

此问题在这里已有答案:

CORS: Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true

大家好,

我遇到了一个用户注册应用的问题,希望你们能帮我解决这个问题:

我正在使用MongoDb,Express,Angular和NodeJs,这是app.js的样子(我还包括显示在Firefox和Chrome中的错误截图)。谢谢

\"enter

var express = require('express');
var bodyParser = require('body-parser');
var app =express();
var user_routes = require('./routes/user');
var follow_routes = require('./routes/follow');
var publication_routes = require('./routes/publication');
var message_routes = require('./routes/message');
app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Authorization, X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Allow-Request-Method');
res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, DELETE');
res.header('Allow', 'GET, POST, OPTIONS, PUT, DELETE');
next();
}); 
app.use('/api', user_routes);
app.use('/api', follow_routes);
app.use('/api', publication_routes);
app.use('/api', message_routes);
module.exports = app;

admin 更改状态以发布 2023年5月20日
0
0 Comments

您应该添加CORS头-请参见https://enable-cors.org/server_expressjs.html

0
0 Comments

使用npm的cors包来白名单URL或允许任何来源的请求。

0