【问题标题】:Express.js response to Angular CORS ErrorExpress.js 对 Angular CORS 错误的响应
【发布时间】:2019-01-16 12:22:26
【问题描述】:

我想要 Express 服务器端重定向 Angular 页面。
我在 localhost:3000 运行 express
本地主机的角度:4200
当 Express 重定向到 Angular localhost:4200
我总是出错

Failed to load http://localhost:4200/login: Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response.


如何让 Angular 接受 cors 响应?

【问题讨论】:

标签: angular


【解决方案1】:

在你的服务器端 express 代码中安装 cors 包

npm install --save cors

在实现 express.js 的所有逻辑的 server.js 或 app.js 文件中使用它

const cors = require('cors');
app.use(cors());

它启用了跨域功能,您可以在其中访问来自另一个域的请求

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2017-08-01
  • 1970-01-01
  • 2023-04-08
  • 2019-08-25
  • 1970-01-01
  • 2017-10-17
  • 2013-12-05
  • 2012-12-24
相关资源
最近更新 更多