Angular 项目配置代理与跨域相关
2022-06-10 本文已影响0人
survivorsfyh
调试 Angular 新项目的时候配置好 proxy-config 后启动发起接口请求但依然抛出了 404 的异常,一波摸索后发现 angular.json 文件内缺少了对代理的配置导致,具体如下:
一.配置 angular.json => options => proxyConfig
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "theory-pe:build",
"proxyConfig": "proxy-config.json"
},
"configurations": {
"production": {
"browserTarget": "theory-pe:build:production"
},
"development": {
"browserTarget": "theory-pe:build:development"
}
},
"defaultConfiguration": "development"
},
二.配置 proxy-config.json
{
"/api": {
"target": "http://192.168.8.209:9001",
"secure": false,
"logLevel": "debug",
"changeOrigin": true
},
}
以上便是此次分享的全部内容,希望能对大家有所帮助!