diff --git a/config.sample.js b/config.sample.js index 378921f..032719f 100644 --- a/config.sample.js +++ b/config.sample.js @@ -708,11 +708,13 @@ module.exports = { }, /* - ADVANCED: Use safe.fiery.me-exclusive cache control. - This will only work properly with certain settings in nginx reverse proxy and Cloudflare. - Do NOT enable unless you know what you are doing. - true: With CDN (Cloudflare) - 2: When NOT using Cloudflare + Enable Cache-Control header tags. + Please consult the relevant codes in lolisafe.js to learn the specifics. + true or 1: Cloudflare (will cache some frontend pages in CDN) + 2: Basic Cache-Control without CDNs + + NOTE: If set to Cloudflare, and auth is specified in "cloudflare" option above, + lolisafe will automatically call Cloudflare API to purge cache of the relevant frontend pages. */ cacheControl: false, diff --git a/lolisafe.js b/lolisafe.js index 9bd46e1..8170cae 100644 --- a/lolisafe.js +++ b/lolisafe.js @@ -183,15 +183,18 @@ if (config.cacheControl) { next() }) - // If using CDN, cache public pages in CDN - if (config.cacheControl !== 2) { - cdnPages.push('api/check') - for (const page of cdnPages) { - safe.use(`/${page === 'home' ? '' : page}`, (req, res, next) => { - res.set('Cache-Control', cacheControls.cdn) - next() - }) - } + switch (config.cacheControl) { + case 1: + case true: + // If using CDN, cache public pages in CDN + cdnPages.push('api/check') + for (const page of cdnPages) { + safe.get(`/${page === 'home' ? '' : page}`, (req, res, next) => { + res.set('Cache-Control', cacheControls.cdn) + next() + }) + } + break } // If serving uploads with node