Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): clean incoming index URL before p…
Browse files Browse the repository at this point in the history
…rocessing 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.
  • Loading branch information
clydin authored and angular-robot[bot] committed May 9, 2023
1 parent ca8e508 commit 45e98a4
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,27 @@ export async function setupServer(
// before the built-in HTML middleware
return () =>
server.middlewares.use(function angularIndexMiddleware(req, res, next) {
if (req.url === '/' || req.url === `/index.html`) {
if (!req.url) {
next();

return;
}

// Parse the incoming request.
// The base of the URL is unused but required to parse the URL.
const parsedUrl = new URL(req.url, 'http://localhost');
let pathname = parsedUrl.pathname;
if (serverOptions.servePath && pathname.startsWith(serverOptions.servePath)) {
pathname = pathname.slice(serverOptions.servePath.length);
if (pathname[0] !== '/') {
pathname = '/' + pathname;
}
}
if (pathname === '/' || pathname === `/index.html`) {
const rawHtml = outputFiles.get('/index.html')?.contents;
if (rawHtml) {
server
.transformIndexHtml(
req.url,
Buffer.from(rawHtml).toString('utf-8'),
req.originalUrl,
)
.transformIndexHtml(req.url, Buffer.from(rawHtml).toString('utf-8'))
.then((processedHtml) => {
res.setHeader('Content-Type', 'text/html');
res.setHeader('Cache-Control', 'no-cache');
Expand Down

0 comments on commit 45e98a4

Please sign in to comment.