非代码文件增加Last-Modified头返回

pull/1/head
yutent 2023-04-28 19:02:23 +08:00
parent d5dcd44fec
commit d1e1084ec1
2 changed files with 21 additions and 5 deletions

View File

@ -248,11 +248,27 @@ export default async function createServer(root = '', conf = {}) {
default: default:
res.setHeader('content-type', MIME_TYPES[ext] || MIME_TYPES.other) res.setHeader('content-type', MIME_TYPES[ext] || MIME_TYPES.other)
let pub_file = join(PUBLIC_DIR, pathname)
let source_file = join(SOURCE_DIR, pathname)
if (fs.isfile(join(PUBLIC_DIR, pathname))) { if (fs.isfile(pub_file)) {
code = fs.cat(join(PUBLIC_DIR, pathname)) code = fs.cat(pub_file)
} else if (fs.isfile(join(SOURCE_DIR, pathname))) { if (code) {
code = fs.cat(join(SOURCE_DIR, pathname)) let stat = fs.stat(pub_file)
res.setHeader(
'Last-Modified',
new Date(stat.mtime).toGMTString()
)
}
} else if (fs.isfile(source_file)) {
code = fs.cat(source_file)
if (code) {
let stat = fs.stat(source_file)
res.setHeader(
'Last-Modified',
new Date(stat.mtime).toGMTString()
)
}
} else { } else {
code = null code = null
} }

View File

@ -1,7 +1,7 @@
{ {
"name": "fite", "name": "fite",
"type": "module", "type": "module",
"version": "0.7.3", "version": "0.7.4",
"bin": { "bin": {
"fite": "index.js" "fite": "index.js"
}, },