You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.
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:
<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!
The text was updated successfully, but these errors were encountered: