boot function Null safety

Future boot(
  1. {required Application application,
  2. int port = 8080}
)

Function used to run a Spark server

Implementation

Future boot({
  required Application application,
  int port = 8080,
}) =>
    HttpServer.bind(InternetAddress.anyIPv4, port).then((server) async {
      var context = Context();
      var uriRouter = UriRouter();
      context.register(uriRouter);
      await application.onInit(context);
      server.listen((httpRequest) async {
        var request = Request(
            method: Method.fromValue(httpRequest.method),
            uri: httpRequest.uri,
            headers: httpRequest.headers,
            body: await utf8.decodeStream(httpRequest),
            container: {});
        var response = await application.onHandle(request);
        httpRequest.response.statusCode = response.statusCode;
        httpRequest.response.headers.clear();
        httpRequest.response.headers.contentType = response.contentType;
        httpRequest.response.headers.contentLength = response.body.length;
        response.headers.forEach(
            (key, value) => httpRequest.response.headers.add(key, value));
        httpRequest.response.write(response.body);
        return httpRequest.response.close();
      });
    });