Serve constructor

Serve({
  1. required Future<Response?> fetch(
    1. Request,
    2. Server
    ),
  2. WebSocketHandler? websocket,
})

Creates a new Bun serve.

Implementation

factory Serve({
  required Future<web.Response?> Function(web.Request, Server) fetch,
  WebSocketHandler? websocket,
}) {
  JSPromise<web.Response?> handle(web.Request request, Server server) {
    return fetch(request, server).toJS;
  }

  final inner = JSObject()
    ..['fetch'] = handle.toJS
    ..['websocket'] = websocket;

  return Serve._(inner);
}