我正在尝试设置我的angular-cli应用程序以使用代理,因此我不需要在我的网络服务器上使用CORS。
我的DotNetCore服务器在端口49274上运行。 我的angular-cli app运行于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" : ""}
}
}
答案 0 :(得分:0)
我有
export const environment = {
production: false,
apiUrl: 'http://localhost:49274/api/'
};
和apiUrl应该是' / api /' ...!我终于开始工作了:))