fix: cache-control broken with cloudflare setting

This commit is contained in:
Bobby Wibowo 2022-07-12 14:52:46 +07:00
parent 0f6409132a
commit e82cf714dd
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF

View File

@ -155,11 +155,15 @@ if (config.cacheControl) {
case true:
// If using CDN, cache public pages in CDN
cdnPages.push('api/check')
for (const page of cdnPages) {
safe.get(`/${page === 'home' ? '' : page}`, async (req, res) => {
res.set('Cache-Control', cacheControls.cdn)
})
}
safe.use((req, res, next) => {
if (req.method === 'GET' || req.method === 'HEAD') {
const page = req.path === '/' ? 'home' : req.path.substring(1)
if (cdnPages.includes(page)) {
res.set('Cache-Control', cacheControls.cdn)
}
}
return next()
})
break
}