Astro hybrid website - Detected rules that are over the 100 rule limit.
I have an Astro hybrid website (static and SSR) that will have over 300 static pages on Cloudflare Pages, with also some SSR functions. Cloudflare is throwing this error on build:
Invalid _routes.json file found at:
Detected rules that are over the 100 rule limit. Please make sure you have a total of 100 include
and exclude rules combined.
I believe astro creates this _routes.json file to make sure the static routes are not invoked by workers, is there a way around this for sites with 100+ static pages?4 Replies
👋 Hi, indeed it's generated by astro to reduce your costs by skipping the function invocation on static assets. Depending on the exact page layout you can either manually edit this file once it's generated, or delete it before uploading (which invokes a function on every page visit, so not recommended).
What I recommend is to manually look at this rule (happy to help if you're ok with sharing it here) and look at options to convert lots of includes to some excludes (eg. if /assets/* is all static, you could combine them into one rule depending on how astro generates them, or if /pages/* is static but /pages/some-page isn't, you can get away with one include and on exclude instead of N-1 includes)
Hi Dani, thanks thats really helpful 👍 , it's mainly page urls that are being excluded and these are coming from a headless CMS so i won't really know them, although i might be able to get away with removing a bulk of them and replacing with /boats/* for example with a post build function.
Alternatively i guess i could exclude all /* and include the functions with /_astro/* and /_worker/*
in general, in most cases it should be safe to include *, as most frameworks have a fallback mechanism to fetch a static asset if none were found/don't have routes so the built-in worker will fetch it
and you can go from there
if you are certain that only _astro/ and _worker/ have dynamic routes, that's a pretty good optimisation
Ah ok makes sense, thanks for the help 🙂