增加对history路由的支持

master
yutent 2023-03-01 15:42:09 +08:00
parent 4ec028cd1f
commit 9c2b9020e7
2 changed files with 13 additions and 4 deletions

View File

@ -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)

View File

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