kotx / render

Cloudflare Worker to proxy and cache requests to R2
MIT License
384 stars 85 forks source link

Allow custom 404 file #19

Closed Erisa closed 1 year ago

Erisa commented 1 year ago

Allows specifying a NOTFOUND_FILE variable to specify a custom file to serve for 404 responses. This incurs an additional read operation for 404 requests (One to find out there's no file, another to fetch the 404 file) and they are not cached so whether you want that or not is up to user preference.

Perhaps we could cache the 404 file itself, rather than the request, which would drop the double operations when the 404 file is cached.

A couple headers are omitted when serving a 404 response, and the range is obviously ignored. That said, the files content type and etc should be intact so you can serve e.g. an image or text file as appropriate to your needs.

This feature is disabled by default to avoid the double read operations without the user opting in to the behaviour. If this were made default in the future, 404.html would be a good standard filename to use.

kotx commented 1 year ago

This looks perfect, thanks for the PR! 🎉