start method

Future<void> start()

Starts the HTTP server and begins watching the config file for changes.

Implementation

Future<void> start() async {
  await _reloadConfig(logReload: false);

  final handler = const Pipeline()
      .addMiddleware(logRequests())
      .addHandler((request) => _handleRequest(request));

  _server = await shelf_io.serve(handler, host, port);
  _server!
    ..autoCompress = true
    ..idleTimeout = const Duration(minutes: 5);

  await _startWatcher();

  stdout.writeln(
      'Mock server listening on http://${_server!.address.host}:${_server!.port}');
  stdout.writeln('Watching ${path.normalize(configPath)} for changes.');
}