From 4e20f28b78c23388fdf6bdcdd918b3981026e7d9 Mon Sep 17 00:00:00 2001 From: Bobby Wibowo Date: Fri, 20 Sep 2019 02:42:08 +0700 Subject: [PATCH] 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". --- lolisafe.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lolisafe.js b/lolisafe.js index 6fef638..0f758cd 100644 --- a/lolisafe.js +++ b/lolisafe.js @@ -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])) })