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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
22 changes: 12 additions & 10 deletions packages/angular/build/src/builders/karma/application_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ 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.
Expand All @@ -78,21 +77,24 @@ class AngularAssetsMiddleware {
}

const file = this.latestBuildFiles.files[pathname];

if (file?.origin === 'disk') {
this.serveFile(file.inputPath, undefined, res);
if (!file) {
next();

return;
} else if (file?.origin === 'memory') {
// Include pathname to help with Content-Type headers.
this.serveFile(`/unused/${url.pathname}`, undefined, res, undefined, file.contents, true);
}

return;
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);
break;
}
} catch (e) {
err = e;
next(e);
}
next(err);
}

static createPlugin(initialFiles: LatestBuildFiles): InlinePluginDef {
Expand Down
Loading