优化H5路由

master
yutent 2023-11-14 19:12:43 +08:00
parent 7e6c0f0123
commit 39b6d0ff75
2 changed files with 18 additions and 2 deletions

View File

@ -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('</head>', HMR_SCRIPT + '</head>')
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)

View File

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