Updated lolisafe.js

If config.cacheControl is enabled, remove Cache-Control header from
error pages.
Fallbacks to Express' default behavior of using "public, max-age=0".
This commit is contained in:
Bobby Wibowo 2019-09-20 02:42:08 +07:00
parent b75deb268f
commit 4e20f28b78
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF

View File

@ -87,6 +87,7 @@ if (config.cacheControl) {
next()
})
// For static assets (and uploads if serving with node)
setHeaders = res => {
res.set('Access-Control-Allow-Origin', '*')
res.set('Cache-Control', cacheControls.default)
@ -139,11 +140,13 @@ safe.use('/api', api)
// Error pages
safe.use((req, res, next) => {
if (config.cacheControl) res.removeHeader('Cache-Control')
res.status(404).sendFile(path.join(paths.errorRoot, config.errorPages[404]))
})
safe.use((error, req, res, next) => {
logger.error(error)
if (config.cacheControl) res.removeHeader('Cache-Control')
res.status(500).sendFile(path.join(paths.errorRoot, config.errorPages[500]))
})