镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

fix(@angular/build): keep proxy entry order and support a string context - #34258

Merged
alan-agius4 merged 2 commits into
angular:mainfrom
aminesbdev:fix/build-proxy-config-normalization
Oct 6, 2026
Merged

alan-agius4 merged 2 commits into
angular:mainfrom
aminesbdev:fix/build-proxy-config-normalization

Conversation

@aminesbdev

Copy link
Copy Markdown
Contributor

PR Checklist

Please check to confirm your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #34257

normalizeProxyConfiguration loses two things when it turns the proxy file into the object Vite expects:

  • Glob keys are converted by adding the regex key and deleting the original one, so every glob entry ends up after the plain and ^ keys. With {"/api/auth/**": ..., "/api/": ...}, /api/auth/login goes to the /api/ target.
  • In the array form, an entry whose context is a single string (context: '/api') is skipped, so nothing is proxied for it. The Webpack-based dev server accepts it.

What is the new behavior?

  • The normalized object is rebuilt in the original order, with glob keys converted in place.
  • A string context is handled like a one-element array.

Each fix is in its own commit with a test in proxy-config_spec.ts. I checked that both tests fail without the fixes: the order test gets OTHER_API_RETURN, and the string context test gets index.html.

The third point of #34257 (globs and query strings) isn't part of this PR. For a trailing /**, picomatch puts a $ inside the generated regex, so it takes more than appending an optional query string, and it changes which requests get proxied.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

A config that relied on globs being tried last, such as a catch-all /** written before more specific plain keys, will now match in the order it's written. That's also how the Webpack-based dev server handles it.

…onfigurations

http-proxy-middleware, which the Webpack-based development server uses,
accepts a single path as `context`. The conversion of the array form
skipped those entries, so they were dropped and nothing was proxied,
without any message.
…iguration

Glob keys were converted to regular expressions by adding the new key and
deleting the old one, which moved every glob entry to the end of the
object. Since Vite proxies a request with the first entry that matches it,
a glob written before a broader plain key could never be used.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the dev-server proxy configuration loading to support a single string context in the Webpack array form of the configuration file. It also ensures that converted glob entries maintain their original order, which is critical for Vite's proxying behavior. Corresponding unit tests have been added to verify these behaviors. Feedback on the changes points out a potential runtime TypeError if normalizedProxy is null or undefined when calling Object.entries(), and suggests adding a defensive check.

Comment thread packages/angular/build/src/utils/load-proxy-config.ts

@alan-agius4 alan-agius4 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@alan-agius4
alan-agius4 merged commit 3871a9d into angular:main Oct 6, 2026
42 checks passed
@alan-agius4

Copy link
Copy Markdown
Collaborator

This PR was merged into the repository. The changes were merged into the following branches:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/build target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants