Astro Info
Astro v5.8.1
Node v22.15.0
System Linux (x64)
Package Manager npm
Output server
Adapter @astrojs/cloudflare
Integrations @sentry/astro
@astrojs/sitemap
Clipboard command not found!
Please manually copy the text above.
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
Bug: 404 Page Returns Error 1042/522 on Cloudflare Pages with Server Mode
Description
Using output: "server" with prerendered 404.astro, non-existent routes return error 1042 (workers.dev) or 522 (proxy) instead of serving the custom 404 page on Cloudflare Pages.
Environment
- Astro 5.x with @astrojs/cloudflare adapter
- Cloudflare Pages deployment
- Server mode with selective prerendering
Reproduction
- Set
output: "server" in astro.config.mjs
- Create 404.astro with
export const prerender = true
- Deploy to Cloudflare Pages
- Visit non-existent route → 522 timeout instead of 404 page
What Works/Doesn't Work
✅ Direct /404 access works
✅ All prerendered pages work
✅ Dev server works perfectly
❌ Any non-existent route fails
Root Cause
Cloudflare Pages routes unknown URLs to Astro server function instead of falling back to static 404.html. Error 1042 suggests the server function may be trying to make internal fetch requests when handling 404s, which Cloudflare Workers prohibits for security reasons ("You can't fetch between workers with the same account").
Attempted Solutions
- Added
_routes.json with explicit routing rules
- Created standalone 404.astro without dependencies
- Verified correct build output (
dist/404.html exists)
- Tested various Cloudflare Pages configurations
- Cache clearing and fresh deployments
- Removed all Astro integrations other than Cloudflare adaptor
- Tried setting output to "static"
All attempts failed - issue persists.
What's the expected result?
Expected vs Actual
- Expected: Serves generated
dist/404.html with 404 status
- Actual:
- Error 1042 on
*.workers.dev URLs
- Error 522 (timeout) when behind Cloudflare proxy
- No function logs in Cloudflare dashboard
Link to Minimal Reproducible Example
https://github.com/millcrest-cto/minimal-404-test
Participation
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
Bug: 404 Page Returns Error 1042/522 on Cloudflare Pages with Server Mode
Description
Using
output: "server"with prerendered 404.astro, non-existent routes return error 1042 (workers.dev) or 522 (proxy) instead of serving the custom 404 page on Cloudflare Pages.Environment
Reproduction
output: "server"in astro.config.mjsexport const prerender = trueWhat Works/Doesn't Work
✅ Direct
/404access works✅ All prerendered pages work
✅ Dev server works perfectly
❌ Any non-existent route fails
Root Cause
Cloudflare Pages routes unknown URLs to Astro server function instead of falling back to static 404.html. Error 1042 suggests the server function may be trying to make internal fetch requests when handling 404s, which Cloudflare Workers prohibits for security reasons ("You can't fetch between workers with the same account").
Attempted Solutions
_routes.jsonwith explicit routing rulesdist/404.htmlexists)All attempts failed - issue persists.
What's the expected result?
Expected vs Actual
dist/404.htmlwith 404 status*.workers.devURLsLink to Minimal Reproducible Example
https://github.com/millcrest-cto/minimal-404-test
Participation