From fba6baf38058f37b9aee113e8ebf180c23fcbc17 Mon Sep 17 00:00:00 2001 From: Denis Golovin Date: Mon, 26 Feb 2024 21:24:45 -0800 Subject: [PATCH] fix: use stream to send files back to browser Signed-off-by: Denis Golovin --- src/authentication-server.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/authentication-server.ts b/src/authentication-server.ts index d91cba2..34009f5 100644 --- a/src/authentication-server.ts +++ b/src/authentication-server.ts @@ -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); + } }); }