withastro / adapters

Home for Astro's core maintained adapters
69 stars 40 forks source link

Astro Cloudflare - Failed to publish your Function. Got error: Error 8000057: Overlapping rules in `_routes.json` are not allowed. #135

Closed smastrom closed 9 months ago

smastrom commented 9 months ago

Astro Info

Astro                    v4.2.1
Node                     v21.5.0
System                   macOS (arm64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/cloudflare
Integrations             @storyblok/astro
                         @astrojs/preact
                         @astrojs/sitemap

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

Hello, I'm developing an Astro website with static pages generated at the following paths:

Any other page is server-side rendered.

In order to avoid the _routes.json 100-entries limit error addressed in withastro/astro#6516, I'm manually excluding the static paths as described in the docs:

adapter: cloudflare({
   routes: {
      exclude: ['/companies/*', '/blog/*'],
   },
})

The redundant paths /companies/ and /blog/ are not stripped away from the generated _routes.json if I have set the following redirect in 404.astro:

---
return Astro.redirect('/', 301)
---

Causing the following deploy error (as /companies/* and /blog/* are also present in the _routes.json file):

Error: Failed to publish your Function. Got error: Error 8000057: Overlapping rules in `_routes.json` are not allowed. Rule "/companies/" is overlapped by "/companies/*". Remove one of the rules to continue.

Generated routes.json

{
  "version": 1,
  "include": [
    "/*"
  ],
  "exclude": [
    "/companies/",
    "/companies/*",
    "/blog/",
    "/blog/*",
    // ...
  ]
}

What's the expected result?

{
  "version": 1,
  "include": [
    "/*"
  ],
  "exclude": [
    "/companies/*",
    "/blog/*",
    // ...
  ]
}

Link to Minimal Reproducible Example

https://stackblitz.com/edit/withastro-astro-cykvsk?file=dist%2F_routes.json

Participation

mattpaz commented 9 months ago

I recently started to test this. I'm encountering the 8000057 issue with the 9.0.0 release.

Overlapping rules in _routes.json are not allowed

Here's my Astro Info:

Astro                    v4.2.6
Node                     v20.11.0
System                   macOS (arm64)
Package Manager          npm
Output                   hybrid
Adapter                  @astrojs/cloudflare
Integrations             @astrojs/tailwind
                         @astrojs/svelte

Thus far, I'm unable to isolate where the point of failure is so far.

I have several /api endpoints, nested sub directories alongside several Astro.redirect touch points. It is mostly SSR alongside a few static touch points.

That probably isn't enough to jog any ideas, but on the chance it provides a eureka moment about some edge cases, I thought I'd provide some preliminary feedback.

If you have any tips/thoughts, let me know.

Thanks!

alexanderniebuhr commented 9 months ago

The overlapping issue should be fixed. You could provide a reproduction example, and I can check.

MehrdadKhnzd commented 9 months ago

Hi! I just started to face the same issue. It was working until recently without any problems. Now, pages x/* and x/*/y (and any other route with the same structure) will throw the exact same error: Error: Failed to publish your Function. Got error: Error 8000057: Overlapping rules in "_routes.json" are not allowed. Rule "/x/*/y" is overlapped by "/x/*". Remove one of the rules to continue. This is totally breaking my software and prevents me from deploying any updates. I came to open a new issue but found this. Please let me know what you think.

alexanderniebuhr commented 9 months ago

This is totally breaking my software and prevents me from deploying any updates. I came to open a new issue but found this. Please let me know what you think.

I'm sorry to hear that. Please open a new issue with a reproducible example for your specific issue using https://astro.new

EskelCz commented 9 months ago

This is totally breaking my software and prevents me from deploying any updates. I came to open a new issue but found this. Please let me know what you think.

I'm sorry to hear that. Please open a new issue with a reproducible example for your specific issue using https://astro.new

@alexanderniebuhr I have the same issue. Astro supports these "overlaps", but it seems these generated _routes don't. Is that something that cloudflare can/will improve, or is that a fundamental limitation and we have to work around it?

My build error:

Error 8000057: Overlapping rules in `_routes.json` are not allowed. Rule "/game/*/form" is overlapped by "/game/*". Remove one of the rules to continue.
alexanderniebuhr commented 9 months ago

Generally it is not an issue. Please also create an example for your specific case. I also want to let you know that the new version of the Cloudflare adapter, currently in development, will have a new _routes.json generation

whoiscarlo commented 7 months ago

This is totally breaking my software and prevents me from deploying any updates. I came to open a new issue but found this. Please let me know what you think.

I'm sorry to hear that. Please open a new issue with a reproducible example for your specific issue using https://astro.new

@alexanderniebuhr I have the same issue. Astro supports these "overlaps", but it seems these generated _routes don't. Is that something that cloudflare can/will improve, or is that a fundamental limitation and we have to work around it?

My build error:

Error 8000057: Overlapping rules in `_routes.json` are not allowed. Rule "/game/*/form" is overlapped by "/game/*". Remove one of the rules to continue.

Any updates on this? @EskelCz were you able to find a work around?

alexanderniebuhr commented 7 months ago

The workaround is to provide your own custom _routes.json file in public/_routes.json. v10 of the adapter which should release this week, should also fix the issue hopefully