Skip to content

Commit

Permalink
fix(vercel): allow non-glob cache rules to apply to / (#908)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Feb 4, 2023
1 parent 10a7ee7 commit 4d89e31
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 4d89e31

Please sign in to comment.