在我的浏览器开发人员工具栏中,我收到以下关于POST请求的错误消息:
Access to XMLHttpRequest at 'http://localhost:8000/api/tags/' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
但是,当我查看server.js时,我却允许访问:
app.prepare().then(() => {
const server = express();
server.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
有人知道为什么现在阻止它
答案 0 :(得分:1)
最好按照以下方式使用“ cors”软件包。
as_adj