From 9c2b9020e7ed1e57356a02c70cec2a8584eab937 Mon Sep 17 00:00:00 2001 From: yutent Date: Wed, 1 Mar 2023 15:42:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=B9history=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 15 ++++++++++++--- package.json | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index b26328f..cb63908 100644 --- a/index.js +++ b/index.js @@ -71,6 +71,7 @@ function createServer() { http .createServer(function (req, res) { let pathname = parse(req.url).pathname.slice(1) + let paths = pathname.split('/') pathname = decode(pathname) || 'index.html' @@ -93,7 +94,17 @@ function createServer() { res.writeHead(200, 'OK') fs.origin.createReadStream(file).pipe(res) } else { - res.setHeader('content-type', MIME_TYPES.html) + if (paths.length > 1 && paths[0].endsWith('.html')) { + let rootFile = join(root, paths[0]) + if (fs.isfile(rootFile)) { + res.setHeader('accept-ranges', 'bytes') + res.setHeader('content-type', MIME_TYPES.html) + res.setHeader('content-length', fs.stat(rootFile).size) + res.writeHead(200, 'OK') + fs.origin.createReadStream(rootFile).pipe(res) + return + } + } res.setHeader('content-length', 0) res.setHeader('x-url', file) res.writeHead(404, 'Not Found') @@ -159,8 +170,6 @@ exports.activate = function (ctx) { if (enabled) { let editor = vsc.window.activeTextEditor if (editor) { - console.log(editor) - let pathname = editor.document.uri.fsPath.slice(root.length) vsc.commands.executeCommand('vscode.open', baseUrl + pathname) diff --git a/package.json b/package.json index fd761dc..4e9e8c3 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "simple-http", "displayName": "simple http", "description": "🔥 简单的http服务器, 方便临时调试html", - "version": "1.3.1", + "version": "1.4.0", "publisher": "yutent", "author": "Yutent [@yutent]", "icon": "logo.png",