From 3cb566ea6add2977450e24b2f990945f5ddbd380 Mon Sep 17 00:00:00 2001 From: Peter Graugaard Date: Wed, 3 Apr 2024 00:45:29 +0200 Subject: [PATCH] fix(cloudflare-pages): use predefined wildcards in `routes.exclude` (#2319) --- src/presets/cloudflare-pages.ts | 4 ++-- test/fixture/nitro.config.ts | 2 +- test/fixture/public/cf-pages-exclude/not-in-routes-json.txt | 2 ++ test/presets/cloudflare-pages.test.ts | 1 + 4 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 test/fixture/public/cf-pages-exclude/not-in-routes-json.txt diff --git a/src/presets/cloudflare-pages.ts b/src/presets/cloudflare-pages.ts index 7378f11796..2c6ba824d4 100644 --- a/src/presets/cloudflare-pages.ts +++ b/src/presets/cloudflare-pages.ts @@ -120,8 +120,8 @@ async function writeCFRoutes(nitro: Nitro) { "_worker.js", "_worker.js.map", "nitro.json", - ...explicitPublicAssets.map((dir) => - withoutLeadingSlash(joinURL(dir.baseURL, "**")) + ...routes.exclude.map((path) => + withoutLeadingSlash(path.replace(/\/\*$/, "/**")) ), ], }); diff --git a/test/fixture/nitro.config.ts b/test/fixture/nitro.config.ts index 069bb7eadc..0de6b427c5 100644 --- a/test/fixture/nitro.config.ts +++ b/test/fixture/nitro.config.ts @@ -107,7 +107,7 @@ export default defineNitroConfig({ pages: { routes: { include: ["/*"], - exclude: ["/blog/static/*"], + exclude: ["/blog/static/*", "/cf-pages-exclude/*"], }, }, }, diff --git a/test/fixture/public/cf-pages-exclude/not-in-routes-json.txt b/test/fixture/public/cf-pages-exclude/not-in-routes-json.txt new file mode 100644 index 0000000000..965acfc444 --- /dev/null +++ b/test/fixture/public/cf-pages-exclude/not-in-routes-json.txt @@ -0,0 +1,2 @@ +This file shouldn't be under "exclude" in the _routes.json outputted by Cloudflare Pages builds. +It's covered by the "/cf-pages-exclude/*" wildcard. diff --git a/test/presets/cloudflare-pages.test.ts b/test/presets/cloudflare-pages.test.ts index d3c98ec9e7..14a579e6bd 100644 --- a/test/presets/cloudflare-pages.test.ts +++ b/test/presets/cloudflare-pages.test.ts @@ -39,6 +39,7 @@ describe.skipIf(isWindows)("nitro:preset:cloudflare-pages", async () => { { "exclude": [ "/blog/static/*", + "/cf-pages-exclude/*", "/build/*", "/_unignored.txt", "/favicon.ico",