2019-12-11 22:46:00 +01:00
|
|
|
const SIX_MONTHS_IN_SECONDS = 15552000;
|
|
|
|
|
|
|
|
const STATIC_ASSET_PATHS = [
|
|
|
|
'/public/font/font-v1.css',
|
|
|
|
'/public/font/v1/300.woff',
|
|
|
|
'/public/font/v1/300i.woff',
|
|
|
|
'/public/font/v1/400.woff',
|
|
|
|
'/public/font/v1/400i.woff',
|
|
|
|
'/public/font/v1/700.woff',
|
|
|
|
'/public/font/v1/700i.woff',
|
|
|
|
'/public/favicon.png',
|
|
|
|
'/public/img/busy.gif',
|
2021-07-19 03:23:32 +02:00
|
|
|
'/public/img/fileRenderPlaceholder.png',
|
2019-12-11 22:46:00 +01:00
|
|
|
'/public/img/gerbil-happy.png',
|
|
|
|
'/public/img/gerbil-sad.png',
|
|
|
|
'/public/img/placeholder.png',
|
2021-07-19 03:42:04 +02:00
|
|
|
'/public/img/placeholderTx.gif',
|
2019-12-11 22:46:00 +01:00
|
|
|
'/public/img/thumbnail-broken.png',
|
|
|
|
'/public/img/thumbnail-missing.png',
|
|
|
|
'/public/img/total-background.png',
|
|
|
|
];
|
2019-12-10 23:05:30 +01:00
|
|
|
|
|
|
|
async function redirectMiddleware(ctx, next) {
|
|
|
|
const {
|
|
|
|
request: { url },
|
|
|
|
} = ctx;
|
|
|
|
|
2021-07-20 11:31:58 +02:00
|
|
|
const HASHED_JS_REGEX = /^\/public\/.*[a-fA-F0-9]{12}\.js$/i;
|
|
|
|
|
|
|
|
if (STATIC_ASSET_PATHS.includes(url) || HASHED_JS_REGEX.test(url)) {
|
2019-12-11 22:46:00 +01:00
|
|
|
ctx.set('Cache-Control', `public, max-age=${SIX_MONTHS_IN_SECONDS}`);
|
2019-12-10 23:05:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return next();
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = redirectMiddleware;
|