fix: cache-control was set to all frontend pages

this now properly sets only on the specific pages that deserves to be
cached in cdn

additionally update sample config file to remove warning about
cacheControl option
this is now mature enough to be simply toggled on/off depending on
your own necessity
This commit is contained in:
Bobby 2022-06-28 13:38:55 +07:00
parent 7c4206a4e2
commit cb2d7b99f7
No known key found for this signature in database
GPG Key ID: 941839794CBF5A09
2 changed files with 19 additions and 14 deletions

View File

@ -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,

View File

@ -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