Skip to content
This repository has been archived by the owner on Jun 20, 2022. It is now read-only.

Commit

Permalink
fix: end response on stream end
Browse files Browse the repository at this point in the history
  • Loading branch information
moughxyz committed Mar 17, 2022
1 parent ebe3fec commit bfa84d9
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions app/javascripts/main/extServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,10 @@ export function normalizeFilePath(requestUrl: string, host: string): string {
const isThirdPartyComponent = requestUrl.startsWith('/Extensions');
const isNativeComponent = requestUrl.startsWith('/components');
if (!isThirdPartyComponent && !isNativeComponent) {
throw new Error(
`URL '${requestUrl}' falls outside of the extensions/features domain.`
);
throw new Error(`URL '${requestUrl}' falls outside of the extensions/features domain.`);
}

const removedPrefix = requestUrl
.replace('/components', '')
.replace('/Extensions', '');
const removedPrefix = requestUrl.replace('/components', '').replace('/Extensions', '');

const base = `${Protocol}://${host}`;
const url = new URL(removedPrefix, base);
Expand Down Expand Up @@ -63,6 +59,9 @@ async function handleRequest(req: IncomingMessage, res: ServerResponse) {
});
const stream = fs.createReadStream(filePath);
stream.on('error', (error: Error) => onRequestError(error, res));
stream.on('end', () => {
res.end();
});
stream.pipe(res);
} catch (error: any) {
onRequestError(error, res);
Expand Down

0 comments on commit bfa84d9

Please sign in to comment.