From d1e1084ec16a22e439e7bec723c8d24769e426fe Mon Sep 17 00:00:00 2001 From: yutent Date: Fri, 28 Apr 2023 19:02:23 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9D=9E=E4=BB=A3=E7=A0=81=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0Last-Modified=E5=A4=B4=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/dev.js | 24 ++++++++++++++++++++---- package.json | 2 +- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/dev.js b/lib/dev.js index fb7332e..806101c 100644 --- a/lib/dev.js +++ b/lib/dev.js @@ -248,11 +248,27 @@ export default async function createServer(root = '', conf = {}) { default: 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))) { - code = fs.cat(join(PUBLIC_DIR, pathname)) - } else if (fs.isfile(join(SOURCE_DIR, pathname))) { - code = fs.cat(join(SOURCE_DIR, pathname)) + if (fs.isfile(pub_file)) { + code = fs.cat(pub_file) + if (code) { + 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 { code = null } diff --git a/package.json b/package.json index 45bfbdd..5f359b1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "fite", "type": "module", - "version": "0.7.3", + "version": "0.7.4", "bin": { "fite": "index.js" },