Skip to content

Commit

Permalink
fix: use stream to send files back to browser
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Golovin <[email protected]>
  • Loading branch information
dgolovin committed Feb 27, 2024
1 parent 0736811 commit fba6baf
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/authentication-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,17 @@ export async function startServer(config: ServerConfig, server: http.Server): Pr
}

function sendFile(res: http.ServerResponse, filepath: string, contentType: string) {
fs.readFile(filepath, (err, body) => {
fs.stat(filepath, (err, stats) => {
if (err) {
console.error(err);
res.writeHead(404);
res.end();
} else {
res.writeHead(200, {
'Content-Length': body.length,
'Content-Length': stats.size,
'Content-Type': contentType,
});
res.end(body);
}
fs.createReadStream(filepath).pipe(res);
}
});
}

0 comments on commit fba6baf

Please sign in to comment.