lbry-desktop/web/middleware/cache-control.js
infinite-persistence d3be8726fc
Add favicon for Google Search results (#7205)
- A side-quest from "7166 improve search metadata".
- The favicon must be from the same domain as the homepage, so the CDN URL couldn't be used, hence the additional upload.
- The favicon also needs to be multiples of 48x48 and above.
    - Wanted to use SVG for the smallest size possible, but seems like Safari does not fully support it. Got Dejan to give me a reasonably-sized PNG.

## Reference
https://developers.google.com/search/docs/advanced/appearance/favicon-in-search#guidelines
2021-10-01 08:09:02 -04:00

38 lines
1 KiB
JavaScript

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', // LBRY icon
'/public/favicon-spaceman.png',
'/public/img/busy.gif',
'/public/img/fileRenderPlaceholder.png',
'/public/img/gerbil-happy.png',
'/public/img/gerbil-sad.png',
'/public/img/placeholder.png',
'/public/img/placeholderTx.gif',
'/public/img/thumbnail-broken.png',
'/public/img/thumbnail-missing.png',
'/public/img/total-background.png',
];
async function redirectMiddleware(ctx, next) {
const {
request: { url },
} = ctx;
const HASHED_JS_REGEX = /^\/public\/.*[a-fA-F0-9]{12}\.js$/i;
if (STATIC_ASSET_PATHS.includes(url) || HASHED_JS_REGEX.test(url)) {
ctx.set('Cache-Control', `public, max-age=${SIX_MONTHS_IN_SECONDS}`);
}
return next();
}
module.exports = redirectMiddleware;