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",