Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 18 additions & 20 deletions packages/angular/build/src/builders/karma/application_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading