fix: cache error

This commit is contained in:
monoid 2023-10-26 22:09:20 +09:00
parent 454850c6b3
commit 22fad337ae
1 changed files with 11 additions and 9 deletions

View File

@ -25,16 +25,18 @@ export const handler: Handlers = {
const mtime = stat.mtime ?? new Date(0); const mtime = stat.mtime ?? new Date(0);
const body = await Deno.readTextFile(path); const body = await Deno.readTextFile(path);
headers.set("last-modified", mtime.toUTCString()); headers.set("last-modified", mtime.toUTCString());
console.log(mtime);
// headers.set("cache-control", "max-age=600");
const ifModifiedSinceValue = req.headers.get("if-modified-since"); // const ifModifiedSinceValue = req.headers.get("if-modified-since");
if ( ifModifiedSinceValue && // if ( ifModifiedSinceValue &&
mtime.getTime() != new Date(ifModifiedSinceValue).getTime() // mtime.getTime() <= new Date(ifModifiedSinceValue).getTime()
){ // ){
return new Response(null, { // return new Response(null, {
status: Status.NotModified, // status: Status.NotModified,
statusText: STATUS_TEXT[Status.NotModified] // statusText: STATUS_TEXT[Status.NotModified]
}) // })
} // }
return new Response(body, {headers}); return new Response(body, {headers});
}, },
}; };