Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

Request: serve index.html or default to directory listing #16

Open
DartBot opened this issue Jun 5, 2015 · 1 comment
Open

Request: serve index.html or default to directory listing #16

DartBot opened this issue Jun 5, 2015 · 1 comment

Comments

@DartBot
Copy link

DartBot commented Jun 5, 2015

<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!

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

1 participant