From 4d89e3155b1c05f738de20bd66f15ecc51fb5b81 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Sat, 4 Feb 2023 10:00:16 -0800 Subject: [PATCH] fix(vercel): allow non-glob cache rules to apply to `/` (#908) --- src/presets/vercel.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/presets/vercel.ts b/src/presets/vercel.ts index d2be2fea22..5a76e038d0 100644 --- a/src/presets/vercel.ts +++ b/src/presets/vercel.ts @@ -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: "(?/)", + 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 || @@ -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, "-"))