serve function

Future<HttpServer> serve(
  1. Handler handler,
  2. RelicAddress address,
  3. int port, {
  4. SecurityContext? securityContext,
  5. int? backlog,
  6. bool shared = false,
  7. bool strictHeaders = false,
  8. String? poweredByHeader,
})

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

If a securityContext is provided an HTTPS server will be started.

See the documentation for HttpServer.bind and HttpServer.bindSecure for more details on address, port, backlog, and shared.

Every response will get a "date" header and an "X-Powered-By" header. If the either header is present in the Response, it will not be overwritten. Pass poweredByHeader to set the default content for "X-Powered-By", pass null to omit this header.

Implementation

Future<io.HttpServer> serve(
  Handler handler,
  RelicAddress address,
  int port, {
  io.SecurityContext? securityContext,
  int? backlog,
  bool shared = false,
  bool strictHeaders = false,
  String? poweredByHeader,
}) async {
  backlog ??= 0;

  var server = await RelicServer.createServer(
    address,
    port,
    securityContext: securityContext,
    backlog: backlog,
    shared: shared,
    strictHeaders: strictHeaders,
    poweredByHeader: poweredByHeader,
  );

  server.mountAndStart(handler);
  return server.server;
}