Skip to content

Commit 45e98a4

Browse files
clydinangular-robot[bot]
authored andcommitted
fix(@angular-devkit/build-angular): clean incoming index URL before processing in esbuild builder
When using the esbuild-based browser application builder with the development server, the incoming URL for the index HTML may contain search parameters or other URL elements that can cause the index HTML content to not be found or processed incorrected by the development server. These elements are cleaned prior to comparison and the original URL is not longer passed to Vite to avoid unneeded Vite specific processing of the content.
1 parent ca8e508 commit 45e98a4

File tree

1 file changed

+18
-6
lines changed
  • packages/angular_devkit/build_angular/src/builders/dev-server

1 file changed

+18
-6
lines changed

packages/angular_devkit/build_angular/src/builders/dev-server/vite-server.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,15 +302,27 @@ export async function setupServer(
302302
// before the built-in HTML middleware
303303
return () =>
304304
server.middlewares.use(function angularIndexMiddleware(req, res, next) {
305-
if (req.url === '/' || req.url === `/index.html`) {
305+
if (!req.url) {
306+
next();
307+
308+
return;
309+
}
310+
311+
// Parse the incoming request.
312+
// The base of the URL is unused but required to parse the URL.
313+
const parsedUrl = new URL(req.url, 'http://localhost');
314+
let pathname = parsedUrl.pathname;
315+
if (serverOptions.servePath && pathname.startsWith(serverOptions.servePath)) {
316+
pathname = pathname.slice(serverOptions.servePath.length);
317+
if (pathname[0] !== '/') {
318+
pathname = '/' + pathname;
319+
}
320+
}
321+
if (pathname === '/' || pathname === `/index.html`) {
306322
const rawHtml = outputFiles.get('/index.html')?.contents;
307323
if (rawHtml) {
308324
server
309-
.transformIndexHtml(
310-
req.url,
311-
Buffer.from(rawHtml).toString('utf-8'),
312-
req.originalUrl,
313-
)
325+
.transformIndexHtml(req.url, Buffer.from(rawHtml).toString('utf-8'))
314326
.then((processedHtml) => {
315327
res.setHeader('Content-Type', 'text/html');
316328
res.setHeader('Cache-Control', 'no-cache');

0 commit comments

Comments
 (0)