serve function

Future<HttpServer> serve(
  1. Handler handler,
  2. Object address,
  3. int port, {
  4. String? poweredByHeader = 'Dart with package:dart_frog',
  5. SecurityContext? securityContext,
})

Starts an HttpServer that listens on the specified address and port and sends requests to handler.

Pass poweredByHeader to set the default content for "X-Powered-By", pass null to omit this header. By default, the header will be:

"X-Powered-By": "Dart with package:dart_frog"

If a securityContext is provided an HTTPS server will be started

Implementation

Future<HttpServer> serve(
  Handler handler,
  Object address,
  int port, {
  String? poweredByHeader = 'Dart with package:dart_frog',
  SecurityContext? securityContext,
}) {
  return shelf_io.serve(
    (shelf.Request request) async {
      final response = await handler(RequestContext._(request));
      return response._response;
    },
    address,
    port,
    poweredByHeader: poweredByHeader,
    securityContext: securityContext,
  );
}