先有一个proxy.config.json文件
{
"/test": {
"target":"http://192.168.51.178:8769", // 这表示代理了这个域名得接口地址
"secure":false,
"changeOrigin":true,
"pathRewrite":{
"^/test":""
}
},
"/category": {
"target":"http://192.168.51.178:21001",
"secure":false,
"changeOrigin":true,
"pathRewrite":{
"^/category":""
}
},
"/user":{
"target":"http://192.168.51.178:9769",
"secure":false,
"changeOrigin":true,
"pathRewrite":{
"^/user":""
}
},
"/order": {
"target":"http://192.168.51.178:21001",
"secure":false,
"changeOrigin":true,
"pathRewrite":{
"^/order":""
}
}
}
在package.json里面
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.config.json", // 加上这话
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
请求接口引用
// 公用 管理员
export const COMMON_HEAD:string = "/test";
export const GET_CAPTCHA_INIT:string = COMMON_HEAD+"/ua/api/backstage/captcha/init";