XMLHttpRequest被CORS策略阻止
我知道这里已经有很多关于这个问题的答案,但是我还不能解决。我已经按照建议安装了Koa中间件来处理它,但是我无法使其正常工作。大多数修复程序都使用express。
这是我的代码:
const app = new Koa();
const options = {
allowedHeaders: ["Origin", "X-Requested-With", "Content-Type", "Accept", "X-Access-Token"],
credentials: true,
methods: "GET,HEAD,OPTIONS,PUT,PATCH,POST,DELETE",
origin: 'http://localhost:4200',
preflightContinue: false
};
const cors = require('koa2-cors');
app.use(cors(options));```
I have tried with options and without, but I still get this: "Access to XMLHttpRequest at 'http://localhost:3001/niceonedude' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource."
Any help greatly appreciated.