{ "/api": { //這裏是前臺調用後端接口時作的代理標識 "target": "localhost:3100", "logLevel": "debug", "secure": false, "changeOrigin": true, "pathRewrite": { "^/api": "" } } }
注意:pathRewrite
部分的配置,"pathRewrite": {"^/api": ""}
若是沒有這部分的配置,那在發送請求的時候,實際請求的地址將會是http://localhost:3100/api/actionapi/
。相較於真實url
,會多出/api
這一部分。 webpack
//這裏的api表示代理標識 //實際的訪問url應該是:http://localhost:3100/actionapi/ const wcfPath = '/api/actionapi/';
"scripts": { "ng": "ng", "build": "ng build --prod --aot --build-optimizer", "start:dev": "ng serve --proxy-config proxy.conf.json --open", "start:aot": "ng serve --prod --aot --proxy-config proxy.conf.json --open", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e" }
再從新npm run start:dev啓動一下項目,應該就能啓用angular反向代理了。git
**順便再補充一下webpack
和angular
的proxy
地址:https://webpack.js.org/configuration/dev-server/#devserver-proxy
https://github.com/angular/angular-cli/wiki/stories-proxy
**github