Request: serve index.html or default to directory listing #15661
Labels
area-pkg
Used for miscellaneous pkg/ packages not associated with specific area- teams.
type-enhancement
A request for a change that isn't a bug
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!
The text was updated successfully, but these errors were encountered: