Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sethladd opened this issue Dec 16, 2013 · 2 comments
Closed

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

sethladd opened this issue Dec 16, 2013 · 2 comments
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

Comments

@sethladd
Copy link
Contributor

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!

@anders-sandholm
Copy link
Contributor

Removed Pkg-http_server label.
Added Pkg-HttpServer label.

@sethladd sethladd added Type-Enhancement area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. labels Feb 7, 2014
@DartBot
Copy link

DartBot commented Jun 5, 2015

This issue has been moved to dart-archive/http_server#16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

4 participants