Search code examples
proxyangular17

How to configure proxy with Angular 17 (esbuild/vite)


I used to use a proxy with Angular <= 16, using webpack.

Switching to Angular 17 and default esbuild/vite, the proxy configuration does not seem to work anymore.

This configuration used to work:

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

I tried the following two ways to provide the config:

  • ng serve --proxy-config proxy.conf.json
  • Setting proxyConfig in angular.json

In both ways the configuration seems to be ignored.

I'm using Angular (including CLI) 17.0.8 and Node v18.17.0.

Thanks for your help!

I tried to provide the proxy configuration to Angular, expected it to proxy the requests, but the request were not proxied.


Solution

  • Add two ** instead one *

    this way:

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