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

Easy way to set directory index file for http_server #18

Open
DartBot opened this issue Jun 5, 2015 · 3 comments
Open

Easy way to set directory index file for http_server #18

DartBot opened this issue Jun 5, 2015 · 3 comments
Assignees

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#15765


It would be really nice to easily set the directory index file for http_server.

Currently we have to do this:

  staticFiles.directoryHandler = (dir, request) {
    // Redirect directory-requests to index.html files.
    var indexUri = new Uri.file(dir.path).resolve('index.html');
    staticFiles.serveFile(new File(indexUri.toFilePath()), request);
  };

In the future, I'd love to be able to do this:

  staticFiles.directoryIndexFilename = 'index.html';

And we could make it also take an array of options:

  staticFiles.directoryIndexFilename = ['index.html', 'home.html'];

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/1343914?v=3" align="left" width="48" height="48"hspace="10"> Comment by sgjesse


We should add the method serveIndexFile to teh VirtualDirectory class as well. Then one can have a custom directory handler which can forward to the index file, e.g.

  staticFiles.directoryHandler = (dir, request) {
    if (...) {
      // Handle some directory requests here.
    } else {
      // Redirect all other directory requests to the index file.
      staticFiles.serveIndexFile(dir, request);
    }
  };

The index files could also have a path component:

  staticFiles.directoryIndexFile = = ['index.html', '/index.html'];

If the file 'index.html' is not found use the index.html in the virtual directory root.


Set owner to @Skabet.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/5479?v=3" align="left" width="48" height="48"hspace="10"> Comment by sethladd


Nice! I look forward to trying this out.

@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

2 participants