Skip to content

Commit

Permalink
fix: allow overriding assets maxAge using route rules
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 15, 2023
1 parent 84da375 commit db6e6c2
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,15 @@ export async function createNitro(config: NitroConfig = {}): Promise<Nitro> {
asset.baseURL = asset.baseURL || "/";
const isTopLevel = asset.baseURL === "/";
asset.fallthrough = asset.fallthrough ?? isTopLevel;
asset.maxAge = asset.maxAge ?? 0;
const routeRule = options.routeRules[asset.baseURL + "/**"];
asset.maxAge =
(routeRule?.cache as { maxAge: number })?.maxAge ?? asset.maxAge ?? 0;
if (asset.maxAge && !asset.fallthrough) {
options.routeRules[asset.baseURL + "/**"] = defu(
options.routeRules[asset.baseURL + "/**"],
{
headers: {
"cache-control": `public, max-age=${asset.maxAge}, immutable`,
},
}
);
options.routeRules[asset.baseURL + "/**"] = defu(routeRule, {
headers: {
"cache-control": `public, max-age=${asset.maxAge}, immutable`,
},
});
}
}

Expand Down

0 comments on commit db6e6c2

Please sign in to comment.