Skip to content

Angular CLI messes up proxy.conf.js regex proxy -settings passed to Vite when using esbuild #26970

Description

@ajkettun

Command

serve

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

Angular CLI messes up proxy.conf.js regex proxy -settings passed to Vite when using esbuild.

^\\/(?!hui).* becomes \^\/(?!hui)\.[^/]*?\/?

Minimal Reproduction

Vite doesn't seem to support glob patterns in proxy.conf.js. It supports regular expressions which would do fine but Angular CLI proxy configuration normalization messes up regular expressions. Normalization is done here:

https://github.com/angular/angular-cli/blob/main/packages/angular_devkit/build_angular/src/utils/load-proxy-config.ts

This step perhaps mistakenly treats regular expressions as globs:

  // TODO: Consider upstreaming glob support
  for (const key of Object.keys(normalizedProxy)) {
    if (isDynamicPattern(key)) {
      const { output } = parseGlob(key);
      normalizedProxy[`^${output}$`] = normalizedProxy[key];
      delete normalizedProxy[key];
    }
  }

Previously with @angular-devkit/build-angular:browser we had:

module.exports = [
  {
    context: "/internal-api",
    target: "http://localhost:8082",
    logLevel: "debug",
    secure: false
  },
  {
    context: "!/hui/**",
    target: "http://localhost:8080",
    logLevel: "debug",
    secure: false
  }
]

With @angular-devkit/build-angular:browser-esbuild something like this should be equivalent if the configuration would go to Vite without changes:

module.exports = {
  "/internal-api": {
    target: "http://localhost:8082",
    secure: false,
  },
  "^\\/(?!hui).*": {
    target: "http://localhost:8080",
    secure: false
  },
  "^\\/$": {
    target: "http://localhost:8080",
    secure: false,
  }
};

Exception or Error

No response

Your Environment

Angular CLI: 17.1.0
Node: 20.11.0
Package Manager: npm 10.2.4
OS: win32 x64

Angular: 17.1.0
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, language-service, material, material-moment-adapter
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1701.0
@angular-devkit/build-angular   17.1.0
@angular-devkit/core            17.1.0
@angular-devkit/schematics      17.1.0
@schematics/angular             17.1.0
ng-packagr                      17.1.1
rxjs                            7.8.1
typescript                      5.3.3
zone.js                         0.14.3

Anything else relevant?

No response

Activity

  1. added 5 commits that reference this issue on Jan 26, 2024
    6a1649a
    894dd13
    3a66953
    ceb5817
    bb32b7e
  2. added 5 commits that reference this issue on Jan 26, 2024
    ed0b573
    69dfcdb
    926e1e2
    6829070
    53ccf55
  3. added 2 commits that reference this issue on Jan 26, 2024
    dbd3984
    a0e3060
  4. clydin commented on Jan 26, 2024

    @clydin
    Member

    Both the negation configuration option and the regular expression option will be available in the next patch release.
    So if preferred, you could leave the proxy configuration in its original form at that time.

  5. added 3 commits that reference this issue on Jan 26, 2024
    6a161da
    822e7a4
    235c840
  6. ajkettun commented on Feb 1, 2024

    @ajkettun
    Author

    Thanks for the fix!

  7. angular-automatic-lock-bot commented on Mar 3, 2024

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  8. locked and limited conversation to collaborators on Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions