From 260c10c33f034b1f6e060fc5f2991589f4e41629 Mon Sep 17 00:00:00 2001 From: KozakLordOfMatrix Date: Thu, 18 Jun 2026 20:25:15 +0300 Subject: [PATCH] perf: use streams for file serving in dev server --- scripts/serve.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/serve.js b/scripts/serve.js index 157c8fad..b55d8237 100644 --- a/scripts/serve.js +++ b/scripts/serve.js @@ -82,12 +82,19 @@ function serve() { return; } const final = stat.isDirectory() ? path.join(safe, "index.html") : safe; - const data = await fsp.readFile(final); + res.writeHead(200, { "content-type": MIME[path.extname(final).toLowerCase()] || "application/octet-stream", "cache-control": "no-cache", }); - res.end(data); + + const stream = fs.createReadStream(final); + stream.pipe(res); + stream.on('error', (err) => { + if (!res.writableEnded) { + res.destroy(); + } + }); } catch (err) { res.writeHead(500, { "content-type": "text/plain" }).end(String(err)); }