Skip to content

refactor: minor code changes in karma AngularAssetsMiddleware #30115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2025
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