Type Alias ServerOptions<WebsocketDataType>

ServerOptions<WebsocketDataType>: {
    middlewares?: Middleware[];
    port?: number;
    routes: (Route | RouteNamespace)[];
    websocket?: WebSocketHandler<WebsocketDataType> & {
        options?: {
            canUpgrade?: ((req: Request) => Promise<boolean>);
            upgrade?: ((req: Request) => Promise<{
                data?: WebsocketDataType;
                headers?: HeadersInit;
            }>);
        };
    };
}

Options for configuring the server.

Type Parameters

  • WebsocketDataType

Type declaration

  • Optionalmiddlewares?: Middleware[]

    An array of middlewares to be applied to the server. Middlewares are executed in the order they are provided.

  • Optionalport?: number

    The port number on which the server should listen.

    3000
    
  • routes: (Route | RouteNamespace)[]

    An array of routes or route namespaces. Routes define the HTTP endpoints served by the server.

  • Optionalwebsocket?: WebSocketHandler<WebsocketDataType> & {
        options?: {
            canUpgrade?: ((req: Request) => Promise<boolean>);
            upgrade?: ((req: Request) => Promise<{
                data?: WebsocketDataType;
                headers?: HeadersInit;
            }>);
        };
    }

    Websocket default Bun options with additional upgrade options allowing to pass headers and data. When upgrade is provided, the websocket handler will be called with the provided headers and data.