Merge into Dream the middleware that rewrites foo/ to foo/index.html
Opened this issue · 5 comments
There is such a middleware in dream-serve:
(* Redirect requests for directories to index.html. *)
let index_html next_handler request =
let rec is_directory path =
match path with
| [""] -> true
| _::suffix -> is_directory suffix
| _ -> false
in
let path = Dream.path request in
if is_directory path then
Dream.redirect request (String.concat "/" (path @ ["index.html"]))
else
next_handler request
There might be some better ways of doing this than just "plopping down" a new middleware in Dream, so maybe it's worth a few minutes of design thought :)
cc @tcoopman because of a related conversation.
Thanks, this is how I currently solve it:
Dream.get "/"
(Dream.from_filesystem "dist" "index.html");
But having something in Dream.static
might be nice?
While we are on this subject. I think most static servers I've used have the ability to list files in the current folder (if index.html available)
While we are on this subject. I think most static servers I've used have the ability to list files in the current folder (if index.html available)
Do you mean if index.html
is not available?
Listing files in the current folder is a security risk so it should not be done by default!
Do you mean if
index.html
is not available?
yes. if index.html
or index.htm
is not available.
And I agree that it shouldn't be the default behavior.
Absolutely agree with not doing it by default. I haven't turned Dream yet into a kind of possible "Apache 1997" that lists files etc. (or even respects .htaccess
), but we can make something that works that way either as a library, or merge it into Dream.
So far, I kept index.html
in dream-serve because that is a static site server, but it looks like many projects will need it.