Skip to content

Commit 004822f

Browse files
committed
refactor: minor code changes in karma AngularAssetsMiddleware
Early exits and reduce optional chaining.
1 parent 11d1f2e commit 004822f

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

Diff for: packages/angular/build/src/builders/karma/application_builder.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ class AngularAssetsMiddleware {
6767
) {}
6868

6969
handle(req: IncomingMessage, res: ServerResponse, next: (err?: unknown) => unknown) {
70-
let err = null;
7170
try {
7271
const url = new URL(`http://${req.headers['host']}${req.url}`);
7372
// Remove the leading slash from the URL path and convert to platform specific.
@@ -78,21 +77,24 @@ class AngularAssetsMiddleware {
7877
}
7978

8079
const file = this.latestBuildFiles.files[pathname];
81-
82-
if (file?.origin === 'disk') {
83-
this.serveFile(file.inputPath, undefined, res);
80+
if (!file) {
81+
next();
8482

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

90-
return;
86+
switch (file.origin) {
87+
case 'disk':
88+
this.serveFile(file.inputPath, undefined, res);
89+
break;
90+
case 'memory':
91+
// Include pathname to help with Content-Type headers.
92+
this.serveFile(`/unused/${url.pathname}`, undefined, res, undefined, file.contents, true);
93+
break;
9194
}
9295
} catch (e) {
93-
err = e;
96+
next(e);
9497
}
95-
next(err);
9698
}
9799

98100
static createPlugin(initialFiles: LatestBuildFiles): InlinePluginDef {

0 commit comments

Comments
 (0)