Request: serve index.html or default to directory listing
<img src="https://avatars.githubusercontent.com/u/5479?v=3" align="left" width="96" height="96"hspace="10"> Issue by sethladd Originally opened as dart-lang/sdk#15661
I'm using the http_server package. I'd like to do the following:
if index.html exists, serve that if not, serve generated directory listing
I can't find an easy way to do this. If I override directoryHandler, then I can't also say "if no index.html, go ahead and use the default of generating an HTML page with links"
Also, because serveFile is off of the instance of VirtualDirectory, I can't use method cascades to set it all up. I wanted to do this:
var staticFiles = new VirtualDirectory('../web') ..directoryHandler = (Directory dir, HttpRequest request) { var path = '${dir.path}${Platform.pathSeparator}index.html'; var file = new File(path); file.exists().then((result) { if (result) { staticFiles.serveFile(file, request); } else { staticFiles. } }); };
Instead I had to do this:
var staticFiles = new VirtualDirectory('../web'); staticFiles.directoryHandler = (Directory dir, HttpRequest request) { var path = '${dir.path}${Platform.pathSeparator}index.html'; var file = new File(path); file.exists().then((result) { if (result) { staticFiles.serveFile(file, request); } else { staticFiles. } }); };
And for what it's worth, it would be a lot easier if I could just say "use index.html as the default file, if it exists" instead of writing all the path and exists() in there. But maybe there's an easier way?
Thanks!
<img src="https://avatars.githubusercontent.com/u/3276024?v=3" align="left" width="48" height="48"hspace="10"> Comment by anders-sandholm
Removed Pkg-http_server label. Added Pkg-HttpServer label.