Attempting to fetch asset that doesn't exist returns index.html

Hi all, If you call ASSETS.fetch(req) in a pages advanced function for an asset that doesn't exist, instead of returning not found it just returns index.html. Is there a way to disable this behaviour? I basically need some way of checking if a static asset exists, and if not continuing instead of returning the asset.
4 Replies
Chaika
Chaika•12mo ago
Hey 👋 You can add a top-level 404.html, and it'll disable its SPA behavior, and you could tell based off the 404 being returned? https://developers.cloudflare.com/pages/configuration/serving-pages/
Serving Pages · Cloudflare Pages docs
Cloudflare Pages includes a number of defaults for serving your Pages sites. This page details some of those decisions, so you can understand how …
benten
bentenOP•12mo ago
perfect! i guess i should have read more of the docs, thank you! is there a way to inspect the response without cloning it though? if i call res.text() and it turns out to be a valid asset i can't reuse the response, right?
Chaika
Chaika•12mo ago
hmm I haven't played around with it before, but I assume it returns a Response which should have status on it, being 404
benten
bentenOP•12mo ago
ok that makes sense. i know when it was returning the index it was a 200 but a 404 should be a 404 thank you!
Want results from more Discord servers?
Add your server