ShelfVirtualDirectory constructor
ShelfVirtualDirectory(
- String folderPath, {
- String defaultFile = 'index.html',
- String default404File = '404.html',
- bool listDirectory = true,
- 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 folderPathdefault404File
: File name that will be served for 404. Default: 404.htmllistDirectory
: Lists files and directories from the folderPathheadersParser
: 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');
}
}