【问题标题】:Deployed Angular app sending request to Node.js backend is throwing an error已部署的 Angular 应用程序向 Node.js 后端发送请求引发错误
【发布时间】:2021-08-11 16:29:51
【问题描述】:

如果我向后端发送请求,这就是我看到的,我使用的是 Angular 12:

Access to XMLHttpRequest at 'https://commapps.herokuapp.com/auth' from origin 'https://ecstatic-engelbart-897f34.netlify.app' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

ERROR Em {headers: dm, status: 0, statusText: "Unknown Error", url: "https://commapps.herokuapp.com/auth", ok: false, …}

【问题讨论】:

  • 您认为您的后端是否为来自该来源的请求设置了正确的Access-Control- 标头?在没有minimal reproducible example 的情况下,您希望我们做什么?
  • this 可能重复?或许可以试试提供的answer

标签: node.js angular


【解决方案1】:

这个问题可以从后端解决。他们必须将您正在使用的端口号列入白名单,最有可能是 4200。

【讨论】:

  • 如何将我正在使用的端口号列入白名单?
  • OP 的来源不包括端口。如果您在生产中使用 Angular 开发服务器(默认为端口 4200)...不要
  • 它应该类似于 CORS_ALLOW_WHITELIST = ( portnumber1, portnumber2 )
猜你喜欢
  • 1970-01-01
  • 2018-08-07
  • 1970-01-01
  • 1970-01-01
  • 2019-03-07
  • 2021-03-03
  • 2019-11-10
  • 1970-01-01
  • 2020-06-15
相关资源
最近更新 更多