mirror of
https://github.com/HangarMC/Hangar.git
synced 2025-01-24 14:24:47 +08:00
fix(frontend): move cache control to route rules
This commit is contained in:
parent
347e72de0c
commit
004d6e2e85
@ -88,6 +88,16 @@ export default defineNuxtConfig({
|
||||
"/oauth/logout": defineProxyAuth(),
|
||||
},
|
||||
},
|
||||
// cache statics for a year
|
||||
routeRules: {
|
||||
"/_nuxt/**": { headers: { "Cache-Control": "max-age=31536000, immutable" } },
|
||||
"/**/*.js": { headers: { "Cache-Control": "max-age=31536000, immutable" } },
|
||||
"/**/*.mjs": { headers: { "Cache-Control": "max-age=31536000, immutable" } },
|
||||
"/**/*.css": { headers: { "Cache-Control": "max-age=31536000, immutable" } },
|
||||
"/**/*.json": { headers: { "Cache-Control": "max-age=31536000, immutable" } },
|
||||
"/**/*.xml": { headers: { "Cache-Control": "max-age=31536000, immutable" } },
|
||||
"/**/*.svg": { headers: { "Cache-Control": "max-age=31536000, immutable" } },
|
||||
},
|
||||
});
|
||||
|
||||
function defineProxyAuth(): ProxyOptions {
|
||||
|
@ -1,8 +0,0 @@
|
||||
export default defineEventHandler((event) => {
|
||||
const statics = 31536000; // 1 year
|
||||
const other = 60 * 60; // 1 hour
|
||||
const url = event.node.req.url;
|
||||
if (url?.startsWith("/api")) return;
|
||||
const maxage = url?.match(/(.+)\.(jpg|jpeg|webp|gif|css|png|js|ico|svg|mjs)/) ? statics : other;
|
||||
event.node.res.setHeader("Cache-Control", `max-age=${maxage} s-maxage=${maxage}`);
|
||||
});
|
Loading…
Reference in New Issue
Block a user