Skip to content

Commit e508144

Browse files
committed
fix: improved handeling of header "last-modified"
1 parent 528bdf9 commit e508144

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ class CoCreateFileSystem {
9898
organization_id
9999
}
100100

101-
102101
let file
103102
if (pathname.startsWith('/dist') || pathname.startsWith('/admin') || ['/403.html', '/404.html', '/offline.html', '/manifest.webmanifest', '/service-worker.js'].includes(pathname))
104103
file = await getDefaultFile(pathname)
@@ -136,6 +135,14 @@ class CoCreateFileSystem {
136135
return sendResponse(pageNotFound.object[0].src, 404, { 'Content-Type': 'text/html' })
137136
}
138137

138+
139+
if (file.modified || file.created) {
140+
let modifiedOn = file.modified.on || file.created.on
141+
if (modifiedOn instanceof Date)
142+
modifiedOn = modifiedOn.toISOString()
143+
res.setHeader('Last-Modified', modifiedOn);
144+
}
145+
139146
let contentType = file['content-type'] || 'text/html';
140147
if (contentType.startsWith('image/') || contentType.startsWith('audio/') || contentType.startsWith('video/')) {
141148
src = src.replace(/^data:image\/(png|jpeg|jpg);base64,/, '');
@@ -148,9 +155,6 @@ class CoCreateFileSystem {
148155
}
149156
}
150157

151-
if (file.modified)
152-
res.setHeader('Last-Modified', file.modified.on);
153-
154158
sendResponse(src, 200, { 'Content-Type': contentType })
155159

156160
function sendResponse(src, statusCode, headers) {

0 commit comments

Comments
 (0)