From 1c3e8f6c3b839087aa51de2e2fb665cd907f2847 Mon Sep 17 00:00:00 2001 From: Richard Simpson Date: Mon, 13 Mar 2023 09:58:21 -0500 Subject: [PATCH] fix: rebase _routes.json for Cloudflare when config.base set (#6473) --- .changeset/sweet-cherries-tickle.md | 5 +++++ packages/integrations/cloudflare/src/index.ts | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .changeset/sweet-cherries-tickle.md diff --git a/.changeset/sweet-cherries-tickle.md b/.changeset/sweet-cherries-tickle.md new file mode 100644 index 000000000..70e6db104 --- /dev/null +++ b/.changeset/sweet-cherries-tickle.md @@ -0,0 +1,5 @@ +--- +'@astrojs/cloudflare': patch +--- + +fix automatic routes generation not respecting config.base diff --git a/packages/integrations/cloudflare/src/index.ts b/packages/integrations/cloudflare/src/index.ts index a72e0db46..f87b701e9 100644 --- a/packages/integrations/cloudflare/src/index.ts +++ b/packages/integrations/cloudflare/src/index.ts @@ -153,7 +153,12 @@ export default function createIntegration(args?: Options): AstroIntegration { .map((file: string) => `/${file}`); for (let page of pages) { - staticPathList.push(prependForwardSlash(page.pathname)); + let pagePath = prependForwardSlash(page.pathname); + if (_config.base !== '/') { + const base = _config.base.endsWith('/') ? _config.base.substring(0, -1) : _config.base; + pagePath = `${base}${pagePath}`; + } + staticPathList.push(pagePath); } const redirectsExists = await fs.promises