ShelfVirtualDirectory constructor

ShelfVirtualDirectory(
  1. String folderPath, {
  2. String defaultFile = 'index.html',
  3. String default404File = '404.html',
  4. bool listDirectory = true,
  5. FileHeaderParser headersParser = _defaultFileheaderParser,
})

Creates a instance of ShelfVirtualDirectory

Parameters

  • folderPath: Name of the directory you want to serve. Must be a absolute path.
  • defaultFile: File name that will be serve. Must be inside folderPath
  • default404File: File name that will be served for 404. Default: 404.html
  • listDirectory: Lists files and directories from the folderPath
  • headersParser: Provide your own headers from the File.

Examples

You can get router or handler or cascade from ShelfVirtualDirectory instance


final virDirRouter = ShelfVirtualDirectory(folderToServe);

final staticFileHandler = const Pipeline()
    .addMiddleware(logRequests())
    .addHandler(virDirRouter.handler);

io.serve(Cascade().add(staticFileHandler).handler,address,port).then((server){
    print('Server is sunning at ${server.address}:${server.port}'),
});

Implementation

ShelfVirtualDirectory(
  this.folderPath, {
  this.defaultFile = 'index.html',
  this.default404File = '404.html',
  this.listDirectory = true,
  FileHeaderParser headersParser = _defaultFileheaderParser,
})  : _dir = Directory(folderPath),
      _headersParser = headersParser {
  if (!_dir.existsSync()) {
    throw ArgumentError('A directory corresponding to folderpath '
        '"$folderPath" could not be found');
  }
}