Astro adapter + Static 404 + _routes.json causing billable usage
Hey all,
I have a pretty standard Astro + Workers setup as outlined in the documentation.
output: server is also set because some pages are dynamic.
The adapter is nice because it autogenerates a _routes.json which automatically segregates static assets (non-billable) between dynamic routes (workers invoked, billable).
To maximize the assets benefit, I also have Astro generate a static /404.html at build time.
However, I noticed in the observability dashboard that Worker functions are being invoked on routes which are 404 — the 404 page does show though. This is a problem because some browsers do request bogus paths for whatever reason (example, devtools.json or favicons, etc (of course these can be remedied by including this file in public)), and users could just spam an invalid path and cause billable invocations.
Investigating this further, I saw that I can configure an assets.not_found_handling to 404-page to help reduce billable usage, but this causes routes defined in _routes.json’s include to no longer invoke and show a 404. To fix this, I must further configure assets.run_worker_first to an array of paths which are more or less the same thing as what’s in _routes.json. This seems to reduce the benefit of the convenience of having these dynamic paths generated for me.
Am I missing a configuration item that will get me the behavior I want? I’d rather not have this duplication if possible.0 Replies