withastro / adapters

Home for Astro's core maintained adapters
47 stars 26 forks source link

Cloudflare `_routes.json` overlapping rules error when upgrading @astrojs/cloudflare `8.1.0` to any `9.x.x` version #202

Closed lucaswalter closed 3 months ago

lucaswalter commented 3 months ago

Astro Info

Astro                    v4.5.9
Node                     v20.11.1
System                   macOS (arm64)
Package Manager          bun
Output                   server
Adapter                  @astrojs/cloudflare
Integrations             @astrojs/tailwind
                         @astrojs/svelte
                         @astrojs/react
                         @astrojs/mdx
                         astro-robots-txt

Describe the Bug

I am getting the following _routes.json overlapping rules error during route on every single of @astrojs/cloudflare greater than 8.1.0 (all 9.X.X version fail to build on cloudflare).

I am able to build and deploy to Cloudflare Pages on 8.1.0. The included repro mimics my site structure.

...
13:24:57.502 | 18:24:57 [build] Server built in 16.91s
13:24:57.503 | 18:24:57 [build] Complete!
13:24:57.617 | Finished
13:24:57.618 | Found _worker.js in output directory. Uploading.
13:24:58.988 | ✨ Compiled Worker successfully
13:24:59.046 | Found _routes.json in output directory. Uploading.
13:24:59.061 | Validating asset output directory
13:24:59.843 | Deploying your site to Cloudflare's global network...
13:25:06.579 | Parsed 3 valid redirect rules.
13:25:07.953 | Uploading... (79/86)
13:25:08.927 | Uploading... (82/86)
13:25:08.941 | Uploading... (84/86)
13:25:09.934 | Uploading... (86/86)
13:25:09.934 | ✨ Success! Uploaded 7 files (79 already uploaded) (2.48 sec)
13:25:09.934 |  
13:25:10.564 | ✨ Upload complete!
13:25:11.937 | Uploading to dependency cache
13:25:11.945 | Skipping build output cache as it's not supported for your project
13:25:13.084 | Success: Dependencies uploaded to build cache.
13:25:14.197 | Success: Assets published!
13:25:16.813 | Error: Failed to publish your Function. Got error: Error 8000057: Overlapping rules in `_routes.json` are not allowed. Rule "/games/best-steam-games-/*" is overlapped by "/games/*". Remove one of the rules to continue.

What's the expected result?

I expect to be able to to upgrade to the most recent version of @astrojs/cloudflare

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-kh3zar?file=src%2Fpages%2Fgames%2F%5Bid%5D%2Findex.astro

Participation

lucaswalter commented 3 months ago

Looking back through my config, I also have these redirects configured in my site's defineConfig() (which is potentially overlapping with the generated routes?)

  redirects: {
    '/games/counter-strike-global-offensive': '/games/counter-strike-2',
    '/games/most-popular-steam-games': '/games/most-played-steam-games',
    '/tools/next-steam-sale': '/sales'
  },