Vite dev server: proxy config normalization reorders glob keys, drops string `context` and misses URLs with a query string
Maintainer thường phản hồi trong vòng 1 ngày
Một pull request liên quan đã được merge.
- #34258 của @aminesbdev — đã merge
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 65/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- angular, node.js, typescript, vite
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- TypeScript
- Star
- 27k
- Fork
- 11.8k
- Merge trung bình
- 1 ngày 46 phút
- Pull request đã merge (30 ngày)
- 160
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của angular/angular-cli
-
area: @angular/cli
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
angular/angular-cli#34263 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Can't use an array of hostnames in --allowedHosts cli parameter in @angular/build:dev-serverĐang mởarea: @angular/build gemini-triaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
angular/angular-cli#33955 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: @angular/cli gemini-triaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
angular/angular-cli#33055 · 1 bình luận · 3 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Two TS linting errors in `main.ts`Có thể đã có người làm @Hangell đã nhận hôm nay. Đang mởarea: @schematics/angular
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 45/100
angular/angular-cli#34267 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Follow-up to issue: SSR: Add a way to configure externalDependencies for the server bundle onlyĐang mởarea: @angular/build
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
angular/angular-cli#34262 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của angular/angular-cli
Issue tương tự
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Small-tailqwq/dsh-deep-whale#187 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Tela Marca manda conferir o campo "Razão social", que em Portugal se chama "Denominação social"Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
melgarafael/DeskcommCRM#2503 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
0x80/isolate-package#218 ·
-
bug via-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
pingdotgg/t3code#16859 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày