Blog Detail

  • Home
  • How to add proxy-config in Angular

How to add proxy-config in Angular

In this post you can see how to add proxy server config in Angular for local. This will be really help you to avoid CORS error in your local. First you have to create proxy.config.json file and this file should be presented in src folder as below. And add this path in angular.json then restart the server

Proxy Config File Path
Proxy Config File Path

proxy.config.json

{
    "/api/*": {
      "target": "http://localhost:8080",
      "secure": false,
      "changeOrigin":true,
      "logLevel": "debug"
      },
      "pathRewrite": {
        "^/api/" : ""
      }
}

angular.json

"serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "fabricmanagement-ui:build",
            "proxyConfig": "src/proxy.conf.json"
          },
          "configurations": {
            "production": {
              "browserTarget": "fabricmanagement-ui:build:production"
            }
          }
        },

Write a comment