I think autoindex is usually the name of this option for a web server. I wish to serve a directory using app.static and the index.html file should be served at the root of the directory.
I don't see an option for this in sanic.
Using app.static 2 times works :
app.static('/public', './public/index.html')
app.static('/public', './public')
So this issue is not critical at all. But I still believe that it is an expected functionality when serving static directories.
I think autoindex is actually when it produces a directory listing _if_ there is no index.html, and otherwise produces the index.html. Is that what you're asking for, or just that the second half, that index.html is exposed via app.static as the root route?
For my use case I was mostly interested in the second half, but yes the 2 things are usually associated.
I am not stuck in any way by this, I just think it is handy and somewhat expected of a web server and therefore might be added to the backlog. For example the static middleware of the express framework has this functionality by default.
I think this issue is a bit stale, but I don't know that based on the use cases I've seen previously with Sanic this is something that would be a high value target. Gonna mark it as a feature request and see what the general interest in adopting it is.
My personal opinion is that Sanic is a framework for developing API centric, web _dynamic_ content. There are a lot of well tested, stable servers that can handle static files (like nginx) and also provide a proxy for your Sanic application. Regarding my use cases, I don't even know why there is a static handler at all.
I was about to open a new issue for this: trying the sample code from https://github.com/huge-success/sanic/issues/374#issuecomment-276552506 raises an IsDirectoryError.
@Juanlu001 Can you open the new issue? Throwing an error is a different problem than the one here.
Seems stale and a feature with low interest. If there is a renewed discussion, perhaps take it to the community forums. Closing for now.
Most helpful comment
Using app.static 2 times works :
So this issue is not critical at all. But I still believe that it is an expected functionality when serving static directories.