From 11a140babb72519a030997b7986946adefd0b824 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Fri, 19 Jul 2024 08:21:22 +0000 Subject: [PATCH] fix(@angular/build): serve HTML files directly Ensure direct requests to HTML files result in them being served. Closes #28063 --- .../src/tools/vite/middlewares/index-html-middleware.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/angular/build/src/tools/vite/middlewares/index-html-middleware.ts b/packages/angular/build/src/tools/vite/middlewares/index-html-middleware.ts index 7b9d275109fe..0dab0136c798 100644 --- a/packages/angular/build/src/tools/vite/middlewares/index-html-middleware.ts +++ b/packages/angular/build/src/tools/vite/middlewares/index-html-middleware.ts @@ -6,6 +6,7 @@ * found in the LICENSE file at https://angular.dev/license */ +import { extname } from 'node:path'; import type { Connect, ViteDevServer } from 'vite'; import { AngularMemoryOutputFiles, @@ -28,13 +29,14 @@ export function createAngularIndexHtmlMiddleware( // Parse the incoming request. // The base of the URL is unused but required to parse the URL. const pathname = pathnameWithoutBasePath(req.url, server.config.base); - if (pathname !== '/' && pathname !== '/index.html') { + const extension = extname(pathname); + if (extension !== '.html') { next(); return; } - const rawHtml = outputFiles.get('/index.html')?.contents; + const rawHtml = outputFiles.get(pathname)?.contents; if (!rawHtml) { next();