Skip to content

Commit 8c1a129

Browse files
fix(@angular/build): skip HTML fallback for dotfile requests
The HTML fallback middleware currently rewrites dotfile requests (e.g., /.env, /.npmrc) to /index.html, returning 200 instead of 404. This change skips the SPA fallback when the last URL path segment starts with a dot, providing a small defense-in-depth improvement for the dev server. Made-with: Cursor
1 parent 4643a8a commit 8c1a129

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

packages/angular/build/src/tools/vite/middlewares/html-fallback-middleware.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ export function angularHtmlFallbackMiddleware(
2727
}
2828

2929
if (req.url) {
30+
// No fallback for dotfile requests (e.g., .env, .npmrc)
31+
const pathname = req.url.split('?')[0];
32+
const lastSegment = pathname.substring(pathname.lastIndexOf('/') + 1);
33+
if (lastSegment.startsWith('.')) {
34+
next();
35+
36+
return;
37+
}
38+
3039
const mimeType = lookupMimeTypeFromRequest(req.url);
3140
if (
3241
(mimeType === 'text/html' || mimeType === 'application/xhtml+xml') &&

0 commit comments

Comments
 (0)