修复一处静态资源路径问题

pull/1/head
yutent 2023-02-16 19:29:49 +08:00
parent 304841a9a0
commit e057a3ae8d
1 changed files with 7 additions and 4 deletions

View File

@ -188,6 +188,8 @@ export default async function createServer(root = '', conf = {}) {
}
if (fs.isfile(file)) {
code = fs.cat(file)
} else if (fs.isfile(join(PUBLIC_DIR, pathname))) {
code = fs.cat(join(PUBLIC_DIR, pathname))
} else {
console.clear()
console.log(cyan(pathname), red(`not found!!!`))
@ -218,11 +220,12 @@ export default async function createServer(root = '', conf = {}) {
if (fs.isfile(join(PUBLIC_DIR, pathname))) {
code = fs.cat(join(PUBLIC_DIR, pathname))
} else if (fs.isfile(join(SOURCE_DIR, 'assets', pathname))) {
code = fs.cat(join(SOURCE_DIR, 'assets', pathname))
} else if (fs.isfile(join(SOURCE_DIR, pathname))) {
code = fs.cat(join(SOURCE_DIR, pathname))
}
if (code === null) {
console.error(pathname, '文件不存在')
console.clear()
console.log(cyan(pathname), red(`not found!!!`))
res.writeHead(404, 'Not Found')
res.end('')
return
@ -265,7 +268,7 @@ export default async function createServer(root = '', conf = {}) {
})
chokidar
.watch([SOURCE_DIR, join(root, './index.html')])
.watch([SOURCE_DIR, PUBLIC_DIR, join(root, './index.html')])
.on('all', (act, filePath) => {
if (ready) {
let file = filePath.slice(SOURCE_DIR.length)