Stream files in serveStatic for lower memory use
This commit is contained in:
+8
-2
@@ -83,7 +83,13 @@ function tryStatic(event, fallthrough) {
|
|||||||
// Everything else
|
// Everything else
|
||||||
else {
|
else {
|
||||||
const mime = mimeTypes.lookup(id)
|
const mime = mimeTypes.lookup(id)
|
||||||
if (typeof mime === "string") defaultContentType(event, mime)
|
if (typeof mime === "string") {
|
||||||
|
if (mime.startsWith("text/")) {
|
||||||
|
defaultContentType(event, mime + "; charset=utf-8") // usually wise
|
||||||
|
} else {
|
||||||
|
defaultContentType(event, mime)
|
||||||
|
}
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
size: stats.size
|
size: stats.size
|
||||||
}
|
}
|
||||||
@@ -94,7 +100,7 @@ function tryStatic(event, fallthrough) {
|
|||||||
const path = join(publicDir, id)
|
const path = join(publicDir, id)
|
||||||
return pugSync.renderPath(event, path, {})
|
return pugSync.renderPath(event, path, {})
|
||||||
} else {
|
} else {
|
||||||
return fs.promises.readFile(join(publicDir, id))
|
return fs.createReadStream(join(publicDir, id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user