Angular-CLI proxy to backend doesn't work

后端 未结 9 1124
不知归路
不知归路 2020-11-28 08:00

https://github.com/angular/angular-cli#proxy-to-backend here is an instruction how to do proxying to backend. I did everything step by step and still requests aren\'t proxie

9条回答
  •  囚心锁ツ
    2020-11-28 08:47

        Please follow below steps
    
        1 In Angular project create a file called  **proxy.cons.json** with content like this:
    
        {
            "/api/*": {
              "target": "http://127.0.0.1:8080",
              "secure": false,
              "logLevel": "debug",
              "changeOrigin": true
            }
          }
    
        2 edit package.json file and add below code
    
          "start": "ng serve --proxy-config proxy.conf.json"
    
    
        3 call your backend api like this
    
           this.http.get('/api/v1/people')
          .map(res => res.json());
    
        4 run npm start or ng serve --proxy-config proxy.conf.json
    

提交回复
热议问题