Angular-CLI proxy to backend doesn't work

后端 未结 9 984
不知归路
不知归路 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:40

    Try the following things, mostly it will be either of these:

    1. Add the following:

      "changeOrigin": true,
      "pathRewrite": {"^/service" : ""}
      
    2. Run

      ng serve --proxy-config proxy.config.json
      
    0 讨论(0)
  • 2020-11-28 08:42

    this work for me proxy.config.json file

    {
    "/api": {
        "target": "http://localhost:3000",
        "secure": false,
        "changeOrigin": true
        }
    }
    

    and add "ng serve --proxy-config proxy.config.json" in package.json and run command npm start

    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题