From 39b6d0ff7552b79b1ad76d3be276696ffc82709a Mon Sep 17 00:00:00 2001 From: yutent Date: Tue, 14 Nov 2023 19:12:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96H5=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 18 +++++++++++++++++- package.json | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 56e94d2..e4e7998 100644 --- a/index.js +++ b/index.js @@ -176,6 +176,22 @@ function createServer() { res.setHeader('content-length', Buffer.byteLength(code)) res.writeHead(200, 'OK') + res.end(code) + return + } + } else { + let indexFile = join(root, 'index.html') + if (fs.isfile(indexFile)) { + code = fs + .cat(indexFile) + .toString() + .replace('', HMR_SCRIPT + '') + + res.setHeader('accept-ranges', 'bytes') + res.setHeader('content-type', MIME_TYPES.html) + res.setHeader('content-length', Buffer.byteLength(code)) + res.writeHead(200, 'OK') + res.end(code) return } @@ -183,7 +199,7 @@ function createServer() { res.setHeader('content-length', 0) res.setHeader('x-url', file) res.writeHead(404, 'Not Found') - res.end('') + res.end(null) } }) .listen(port) diff --git a/package.json b/package.json index 1580c21..2f1f277 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "simple-http", "displayName": "simple http", "description": "🔥 简单的http服务器, 方便临时调试html", - "version": "1.5.2", + "version": "1.5.3", "publisher": "yutent", "author": "Yutent [@yutent]", "icon": "logo.png",