【发布时间】:2021-10-24 08:55:20
【问题描述】:
我正在开发一个 web 应用程序的后端,我已经为任何路由设置了全局标头,如下所示
Router.js 文件
Router.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Headers",
"Origin, Accept, Accept-Version,Set-Cookie, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version, X-Response-Time, X-PINGOTHER, X-CSRF-Token,Authorization"
);
res.header("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS");
res.header("Content-Type", "application/json");
res.header("Access-Control-Allow-Credentials", true);
next();
});
服务器.js
//user defined middlewares
app.use("/",Router);
我是否需要再次设置 cors,因为我已经允许从任何来源访问?我还允许飞行前请求
【问题讨论】: