Vite dev server: proxy config normalization reorders glob keys, drops string `context` and misses URLs with a query string
Maintainer antworten meist innerhalb von 1 Tag
Ein zugehöriger Pull Request wurde bereits gemerged.
- #34258 von @aminesbdev — gemerged
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 65/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- angular, node.js, typescript, vite
Rechercherichtung
Start with packages/angular/build/src/utils/load-proxy-config.ts and inspect normalizeProxyConfiguration, then trace how Vite matches proxy patterns against request URLs. Check existing proxy configuration tests and run the relevant tests for ordering, string context, and query strings. Done means all three reproductions proxy to the expected backend without changing unrelated matching behavior.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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
The webpack-based @angular-devkit/build-angular:dev-server
Description
normalizeProxyConfiguration in packages/angular/build/src/utils/load-proxy-config.ts turns the proxy file into the object Vite expects. Three things get lost along the way. In each case the request isn't proxied and falls through to the app (index.html), and nothing shows up in the ng serve output.
- Glob entries lose their position. Each glob key is replaced with
normalizedProxy[pattern] = …; delete normalizedProxy[key], which moves it to the end of the object. Vite uses the first entry that matches, so a specific glob written first loses to a broader plain key written after it. - A string
contextdrops the whole entry. In the array form, an entry whosecontextisn't an array is skipped. webpack-dev-server passescontextto http-proxy-middleware aspathFilter, which accepts a single string, socontext: '/legacy'works there. The array form conversion was added after #25337 so that webpack-style configs keep working, and this case slipped through. - Globs are matched against the URL including its query string. The regex built by picomatch ends with
$and Vite tests it againstreq.url, so/search/**matches/searchbut not/search?q=angular. http-proxy-middleware matches both globs and plain keys against the pathname only.
Minimal Reproduction
A new app served by @angular/build:dev-server, plus a backend that echoes the port and URL it receives:
// backend.mjs
import http from 'node:http';
for (const port of [3998, 3999]) {
http.createServer((req, res) => res.end(`${port} got ${req.url}\n`)).listen(port);
}
1. Order with ng serve --proxy-config proxy.conf.json:
{
"/api/auth/**": {"target": "http://localhost:3998"},
"/api/": {"target": "http://localhost:3999"}
}
curl localhost:4200/api/auth/login returns 3999 got /api/auth/login. I expected it to go to 3998.
2. String context with ng serve --proxy-config proxy.conf.mjs:
export default [{context: '/legacy', target: 'http://localhost:3999'}];
curl localhost:4200/legacy/users returns index.html. loadProxyConfiguration returns {} for this file.
3. Query string with ng serve --proxy-config proxy.conf.json:
{
"/search/**": {"target": "http://localhost:3999"}
}
curl localhost:4200/search is proxied, but curl 'localhost:4200/search?q=angular' returns index.html.
Exception or Error
None. The requests are just not proxied.
Your Environment
Angular CLI : 22.2.0
Angular : 22.2.0
Node.js : 24.21.0
Package Manager : npm 11.19.0
Operating System : darwin arm64
@angular/build : 22.2.0
@angular/cli : 22.2.0
vite : 8.3.0
The code is the same on main.
Anything else relevant?
#34258 fixes the first two points. The third one isn't part of it: 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.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 27k
- Forks
- 11.8k
- Ø Merge
- 1 T. 46 Min.
- Gemergte PRs (30 T.)
- 160
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus angular/angular-cli
-
area: @angular/cli
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 78/100
angular/angular-cli#34263 ·
Maintainer antworten meist innerhalb von 1 Tag
-
area: @angular/build gemini-triaged
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
angular/angular-cli#33955 ·
Maintainer antworten meist innerhalb von 1 Tag
-
area: @angular/cli gemini-triaged
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
angular/angular-cli#33055 · 1 Kommentar · 3 Reaktionen ·
Maintainer antworten meist innerhalb von 1 Tag
-
Two TS linting errors in `main.ts`Evtl. vergeben @Hangell hat das heute übernommen. Offenarea: @schematics/angular
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 45/100
angular/angular-cli#34267 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Follow-up to issue: SSR: Add a way to configure externalDependencies for the server bundle onlyOffenarea: @angular/build
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
angular/angular-cli#34262 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in angular/angular-cli
Ähnliche Issues
-
refactor
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
tomnewport/memprot-topo#55 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
WalletConnect/walletconnect-monorepo#7368 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
BU-Spark/se-chem-apll#47 ·
-
embed: handleTurboSignMessage header comment says the signing page posts to '*' (it never does)Offendocumentation
Schwierigkeit 2/5 Unter einer Stunde Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 Ein halber Tag Anfängerfreundlichkeit 70/100
udistrital/paginaweb_root#23 ·