解决node.js的跨域问题

tech2024-12-26  14

只要把下面的代码卸载app.js上 所有的跨域问题都可以解决。

app.all('*', (req, res, next)=> { res.header("Access-Control-Allow-Origin", req.headers.origin); res.header("Access-Control-Allow-Credentials", true); res.header("Access-Control-Allow-Headers", "X-Requested-With,Content-Type"); res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS"); res.header("Content-Type", "application/json;charset=utf-8"); res.header("X-Powered-By", ' 3.2.1') next(); });
最新回复(0)