From 86068ab18e4a82754dbd055ebf21e3a1ec5ead07 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 11 Oct 2023 09:47:00 -0300 Subject: write: live-dev-server: end file responses less enthusiastically This seems to be a bit more reliable, although it'll probably take a little more memory while serving larger files. --- src/write/build-modes/live-dev-server.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/write/build-modes/live-dev-server.js b/src/write/build-modes/live-dev-server.js index d4efd177..1339c322 100644 --- a/src/write/build-modes/live-dev-server.js +++ b/src/write/build-modes/live-dev-server.js @@ -1,8 +1,6 @@ import * as http from 'node:http'; -import {createReadStream} from 'node:fs'; -import {stat} from 'node:fs/promises'; +import {readFile, stat} from 'node:fs/promises'; import * as path from 'node:path'; -import {pipeline} from 'node:stream/promises' import {logInfo, logWarn, progressCallAll} from '#cli'; import {watchContentDependencies} from '#content-dependencies'; @@ -224,7 +222,7 @@ export async function go({ 'gif': 'image/gif', 'ico': 'image/vnd.microsoft.icon', 'jpg': 'image/jpeg', - 'jpeg:': 'image/jpeg', + 'jpeg': 'image/jpeg', 'js': 'text/javascript', 'mjs': 'text/javascript', 'mp3': 'audio/mpeg', @@ -249,13 +247,12 @@ export async function go({ try { const {size} = await stat(filePath); + const buffer = await readFile(filePath) response.writeHead(200, contentType ? { 'Content-Type': contentType, 'Content-Length': size, } : {}); - await pipeline( - createReadStream(filePath), - response); + response.end(buffer); if (loudResponses) console.log(`${requestHead} [200] ${pathname}`); } catch (error) { response.writeHead(500, contentTypePlain); -- cgit 1.3.0-6-gf8a5