http_server icon indicating copy to clipboard operation
http_server copied to clipboard

Easy way to set directory index file for http_server

Open DartBot opened this issue 9 years ago • 3 comments

<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 avatar Jun 05 '15 22:06 DartBot

<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 avatar Jun 05 '15 22:06 DartBot