exclude assets dir from raster redirects (#9409)

This commit is contained in:
chris48s
2023-07-24 13:15:05 +01:00
committed by GitHub
parent d882433fd9
commit c7efb27086

View File

@@ -362,20 +362,23 @@ class Server {
}) })
if (!rasterUrl) { if (!rasterUrl) {
camp.route(/^\/((?!img\/)).*\.png$/, (query, match, end, request) => { camp.route(
makeSend( /^\/((?!img|assets\/)).*\.png$/,
'svg', (query, match, end, request) => {
request.res, makeSend(
end, 'svg',
)( request.res,
makeBadge({ end,
label: '404', )(
message: 'raster badges not available', makeBadge({
color: 'lightgray', label: '404',
format: 'svg', message: 'raster badges not available',
}), color: 'lightgray',
) format: 'svg',
}) }),
)
},
)
} }
camp.notfound(/(\.svg|\.json|)$/, (query, match, end, request) => { camp.notfound(/(\.svg|\.json|)$/, (query, match, end, request) => {
@@ -412,18 +415,21 @@ class Server {
if (rasterUrl) { if (rasterUrl) {
// Redirect to the raster server for raster versions of modern badges. // Redirect to the raster server for raster versions of modern badges.
camp.route(/^\/((?!img\/)).*\.png$/, (queryParams, match, end, ask) => { camp.route(
ask.res.statusCode = 301 /^\/((?!img|assets\/)).*\.png$/,
ask.res.setHeader( (queryParams, match, end, ask) => {
'Location', ask.res.statusCode = 301
rasterRedirectUrl({ rasterUrl }, ask.req.url), ask.res.setHeader(
) 'Location',
rasterRedirectUrl({ rasterUrl }, ask.req.url),
)
const cacheDuration = (30 * 24 * 3600) | 0 // 30 days. const cacheDuration = (30 * 24 * 3600) | 0 // 30 days.
ask.res.setHeader('Cache-Control', `max-age=${cacheDuration}`) ask.res.setHeader('Cache-Control', `max-age=${cacheDuration}`)
ask.res.end() ask.res.end()
}) },
)
} }
if (redirectUrl) { if (redirectUrl) {