【发布时间】:2019-12-24 17:12:31
【问题描述】:
我有带有客户端的 MEAN 堆栈应用程序(端口 4200 上的实时服务器)并在端口 5000 上侦听快速服务器。现在我已经安装了 CORS 并启用了它,但是每次客户端发出 POST/GET 请求时,它都会以被屏蔽了。
客户:
uri = 'http://localhost:5000/api';
login (user) {
return this.http.post(`${this.uri}/login`, user,{withCredentials: true});
}
服务器:
const cors = require('cors');
app.use(cors({origin:["localhost:4200"], credentials: true}))
错误信息:
Access to XMLHttpRequest at 'http://localhost:5000/api/login' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
【问题讨论】: