in example/example.dart [13:55]
void main(List<String> args) {
final parser = _getParser();
int port;
bool logging;
bool listDirectories;
try {
final result = parser.parse(args);
port = int.parse(result['port'] as String);
logging = result['logging'] as bool;
listDirectories = result['list-directories'] as bool;
} on FormatException catch (e) {
stderr
..writeln(e.message)
..writeln(parser.usage);
// http://linux.die.net/include/sysexits.h
// #define EX_USAGE 64 /* command line usage error */
exit(64);
}
if (!FileSystemEntity.isFileSync('example/example.dart')) {
throw StateError('Server expects to be started the '
'root of the project.');
}
var pipeline = const shelf.Pipeline();
if (logging) {
pipeline = pipeline.addMiddleware(shelf.logRequests());
}
String? defaultDoc = _defaultDoc;
if (listDirectories) {
defaultDoc = null;
}
final handler = pipeline.addHandler(createStaticHandler('example/files',
defaultDocument: defaultDoc, listDirectories: listDirectories));
io.serve(handler, 'localhost', port).then((server) {
print('Serving at http://${server.address.host}:${server.port}');
});
}