【发布时间】:2018-11-05 17:04:21
【问题描述】:
我正在尝试将我的 angular-cli 应用设置为使用代理,因此我的网络服务器上不需要 CORS。
我的 DotNetCore 服务器在端口 49274 上运行。 我的 angular-cli 应用程序在 4200 上运行
我很确定代理可以消除 CORS 错误...
但我仍然收到 CORS 错误...
beer/list:1 Failed to load http://localhost:49274/api/beer: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
core.js:1601 ERROR HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: "Unknown Error", url: null, ok: false, …}
这是我尝试过的配置列表...
{
"/api": {
"target": "http://localhost:49274",
"secure": false
}
}
{
"/api/*": {
"target": "http://localhost:49274",
"secure": false
}
}
{
"/api": {
"target": "http://localhost:49274",
"secure": false,
"changeOrigin": true
}
}
{
"/api/*": {
"target": "http://localhost:49274",
"secure": false,
"changeOrigin": true
}
}
{
"/api": {
"target": "http://localhost:49274",
"secure": false,
"changeOrigin": true,
"pathRewrite": {"^/api" : "http://localhost:49274/api"}
}
}
{
"/api/*": {
"target": "http://localhost:49274",
"secure": false,
"changeOrigin": true,
"pathRewrite": {"^/api" : "http://localhost:49274/api"}
}
}
{
"/api": {
"target": "http://localhost:49274",
"secure": false,
"changeOrigin": true,
"pathRewrite": {"^/api" : ""}
}
}
{
"/api/*": {
"target": "http://localhost:49274",
"secure": false,
"changeOrigin": true,
"pathRewrite": {"^/api" : ""}
}
}
【问题讨论】:
标签: angular .net-core http-proxy