angular反向代理

第一步:根目录新建 proxy.conf.json

target:就是代理的服务器地址。

接口地址必须是http://localhost:8081/api开头

{
    "/api":{
        "target":"http://localhost:8081",
        "changeOrigin":true
    }
}

第二步:
在package.json里配置如下代码

"scripts": {
    "ng": "ng",
    "start": "ng serve --proxy-config proxy.conf.json",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  }

第三步:输入以下命令开启

npm start

猜你喜欢

转载自www.cnblogs.com/hibiscus-ben/p/10348829.html
今日推荐