Skip to content

Commit 7d270b8

Browse files
authored
fix: use stream to send files back to browser (#58)
Signed-off-by: Denis Golovin <[email protected]>
1 parent 5248021 commit 7d270b8

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/authentication-server.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,17 @@ export async function startServer(config: ServerConfig, server: http.Server): Pr
111111
}
112112

113113
function sendFile(res: http.ServerResponse, filepath: string, contentType: string) {
114-
fs.readFile(filepath, (err, body) => {
114+
fs.stat(filepath, (err, stats) => {
115115
if (err) {
116116
console.error(err);
117117
res.writeHead(404);
118118
res.end();
119119
} else {
120120
res.writeHead(200, {
121-
'Content-Length': body.length,
121+
'Content-Length': stats.size,
122122
'Content-Type': contentType,
123123
});
124-
res.end(body);
125-
}
124+
fs.createReadStream(filepath).pipe(res);
125+
}
126126
});
127127
}

0 commit comments

Comments
 (0)