diff --git a/packages/angular/build/src/builders/karma/application_builder.ts b/packages/angular/build/src/builders/karma/application_builder.ts index 2c9c86067e6c..a32f474fa535 100644 --- a/packages/angular/build/src/builders/karma/application_builder.ts +++ b/packages/angular/build/src/builders/karma/application_builder.ts @@ -67,32 +67,30 @@ class AngularAssetsMiddleware { ) {} handle(req: IncomingMessage, res: ServerResponse, next: (err?: unknown) => unknown) { - let err = null; - try { - const url = new URL(`http://${req.headers['host']}${req.url}`); - // Remove the leading slash from the URL path and convert to platform specific. - // The latest build files will use the platform path separator. - let pathname = url.pathname.slice(1); - if (isWindows) { - pathname = pathname.replaceAll(path.posix.sep, path.win32.sep); - } + const url = new URL(`http://${req.headers['host']}${req.url}`); + // Remove the leading slash from the URL path and convert to platform specific. + // The latest build files will use the platform path separator. + let pathname = url.pathname.slice(1); + if (isWindows) { + pathname = pathname.replaceAll(path.posix.sep, path.win32.sep); + } - const file = this.latestBuildFiles.files[pathname]; + const file = this.latestBuildFiles.files[pathname]; + if (!file) { + next(); - if (file?.origin === 'disk') { - this.serveFile(file.inputPath, undefined, res); + return; + } - return; - } else if (file?.origin === 'memory') { + switch (file.origin) { + case 'disk': + this.serveFile(file.inputPath, undefined, res); + break; + case 'memory': // Include pathname to help with Content-Type headers. this.serveFile(`/unused/${url.pathname}`, undefined, res, undefined, file.contents, true); - - return; - } - } catch (e) { - err = e; + break; } - next(err); } static createPlugin(initialFiles: LatestBuildFiles): InlinePluginDef {