app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
res.header("X-Powered-By",' 3.2.1')
res.header("Content-Type", "application/json;charset=utf-8");
next();
});
复制代码转载于:https://juejin.im/post/5cb14a23f265da03b8584101
本文介绍了一种在Node.js应用中实现跨域资源共享(CORS)的方法,通过设置HTTP响应头来允许所有来源的请求,并支持多种HTTP方法。此外,还详细说明了如何设置Content-Type为JSON格式。
772

被折叠的 条评论
为什么被折叠?



