deno_std icon indicating copy to clipboard operation
deno_std copied to clipboard

try_files for @std/http/file_server

Open redabacha opened this issue 1 year ago • 4 comments

Is your feature request related to a problem? Please describe.

there is currently no built-in way to attempt to serve a file from a directory and then handle when the file doesn't exist.

Describe the solution you'd like

a function similar to serveDir or serveDir itself but will throw or hand off back in some way to the caller to deal with when a file is missing, similar to the try_files directive in nginx.

Describe alternatives you've considered

building my own solution but i feel this would be a common enough use case to have as part of the standard library.

redabacha avatar Aug 30 '24 16:08 redabacha

Are you using serveDir() or using @std/http/file-server as a script? Please clarify. It seems you're using serveDir(). In that case, serveDir() serves a HTTP 404 Not Found response. If anything, I could understand perhaps adding a notFoundHandler option to serveDir().

iuioiua avatar Sep 02 '24 23:09 iuioiua

hi @iuioiua, yes that is correct i was referring to the serveDir() function being used in a running application. for existing reference, hono have a onNotFound handler as an option for serveStatic in all their supported runtimes, e.g. https://hono.dev/docs/getting-started/deno#onnotfound.

redabacha avatar Sep 03 '24 17:09 redabacha

WDYT about a notFoundHandler option, @kt3k?

iuioiua avatar Sep 03 '24 23:09 iuioiua

The option like that makes sense to me

kt3k avatar Sep 04 '24 03:09 kt3k