Skip to content

Commit

Permalink
fix(vercel): allow non-glob cache rules to apply to /
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Feb 3, 2023
1 parent f7eed65 commit 5a185ab
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/presets/vercel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@ function generateBuildConfig(nitro: Nitro) {
dest: generateEndpoint(key) + "?url=$url",
};
}),
// If we are using a prerender function for /, then we need to write this explicitly
...(nitro.options.routeRules["/"]?.cache
? [
{
src: "(?<url>/)",
dest: "/__nitro-index",
},
]
: []),
// If we are using a prerender function as a fallback, then we do not need to output
// the below fallback route as well
...(!nitro.options.routeRules["/**"]?.cache ||
Expand All @@ -209,6 +218,9 @@ function generateBuildConfig(nitro: Nitro) {
}

function generateEndpoint(url: string) {
if (url === "/") {
return "/__nitro-index";
}
return url.includes("/**")
? "/__nitro-" +
withoutLeadingSlash(url.replace(/\/\*\*.*/, "").replace(/[^a-z]/g, "-"))
Expand Down

0 comments on commit 5a185ab

Please sign in to comment.