start method

Future start([
  1. Function? callback
])

Implementation

Future start([Function? callback]) async {
  final Directory appDir = await getApplicationDocumentsDirectory();
  final Directory httpDirectory =
      await Directory('${appDir.path}/www').create(recursive: true);
  final VirtualDirectory staticFiles = VirtualDirectory(httpDirectory.path)
    ..allowDirectoryListing = true;
  _httpDirectory = httpDirectory;

  await runZoned(() async {
    if (_server == null) {
      final HttpServer server =
          await HttpServer.bind(InternetAddress.loopbackIPv4, 3000);

      server.listen(staticFiles.serveRequest);

      _server = server;
      host = 'http://${server.address.host}:${server.port}';
      active = true;
      if (callback != null) callback(true);
    }
  }, onError: (e, stackTrace) {
    print('Error occured : $e $stackTrace');
  });
}