Skip to content

Instantly share code, notes, and snippets.

@ShaiYer
Last active October 26, 2023 07:29
Show Gist options
  • Save ShaiYer/d919698b88991113c6f3fa1083ed8950 to your computer and use it in GitHub Desktop.
Save ShaiYer/d919698b88991113c6f3fa1083ed8950 to your computer and use it in GitHub Desktop.
Angular Proxy for API CORS

Generate Proxy for development environment to avoid CORS issues

  • Create file src/proxy.conf.json in the root of the Angular App / Project
  • Define proxy configuration values in angular.json

angular.json

"serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "todo:build",
            "proxyConfig": "projects/todo/src/proxy.conf.json"
          },
          "configurations": {
            "production": {
              "browserTarget": "todo:build:production"
            },
            "development": {
              "browserTarget": "todo:build:development"
            }
          },
          "defaultConfiguration": "development"
        },
{
"/api/v1/*": {
"target": "http://localhost:3000",
"pathRewrite": { "^/api/v1": "" },
"secure": false,
"logLevel": "debug",
"changeOrigin": true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment