-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to set default page in static request #1346
Comments
Make a handler for |
@essen Yes, but i think it's very cumbersome . [
{"/user/[...]", user_router, []},
{"/",cowboy_static,{file,"/www/index.html"}},
{"/web/",cowboy_static,{file,"/www/web/index.html"}},
{"/mobile/",cowboy_static,{file,"/www/mobile/index.html"}},
{"/[...]" , cowboy_static, {dir,"/www"}
] |
@jeromedes {"/[...]" , cowboy_static, {dir,"/www"},[{default,"index.html"}]} when visit |
No I'm not going to add an option like this. If any rewrite has to be added to Cowboy it should occur long before, at the stream handler level, and be more general than finding an index.html file. |
Why close? The issue remains and there's no other issue tracking this. |
Sorry , i think this is not an urgent issue, so ... {"/[...]" , cowboy_static, {dir,"/www",[{index,"index.html"}]}} |
I'd be interested in (and happy to provide PRs to) enriching cowboy_static. A use case that I currently have (and use custom handlers for) is adding headers to the response when serving static content. I suspect there are lots of similar modules across lots of cowboy users that could be made obsolete :) Let me know if you want help / have decided a strategy. |
Please open a separate ticket for each additional feature you think is needed. In this particular ticket the solution can be generalized to a rewrite stream handler that would work for more than cowboy_static for example, and it's possible your changes can as well. In general I'd like to keep |
@boboxiaodd Yes like with most web servers which have a way to configure a default file like
|
Hm I was looking into making an index-specific stream handler but we are lacking information necessary to do this. It has to be done after routing, no choice. Which comforts me in the idea that it should just be done via some kind of rewrite functionality. Maybe the configuration of a [{PathPrefix, [RewriteFun], How}]
PathPrefix :: binary()
RewriteFun :: fun((PathSuffix) -> {true, PathSuffix} | false)
How :: internal | 300..399 If the path prefix matches, then the rest of the path is given to all the funs defined and they can return whether a rewrite should happen. When a rewrite happens it can either occur internally or create a redirect response. Maybe a This could be used for more than index functionality, like ensuring there's a forward slash or all the usual rewrite use cases. Thoughts? |
just like:
http://127.0.0.1/
redirect to:
http://127.0.0.1/index.html
The text was updated successfully, but these errors were encountered: