Skip to main content

Class: BunRouter

Defined in: service-core/src/http/bun/BunRouter.ts:119

Bun-native HTTP/WebSocket router built on Bun.serve(). Exposes the same public surface as the uWS-backed HttpRouter (use/get/post/put/delete/patch/head/options/ws/listen/close/isListening/ listenPort) so RouteUtils.registerRoute() and Server.ts work against either implementation unchanged.

Unlike uWS, Bun.serve() has no built-in dynamic router, so this class maintains its own route table matched inside a single fetch() callback, with static-segment > :param > /* wildcard precedence — replicating uWS's specificity-based matching.

Implements

Indexable

[key: string]: any

Constructors

Constructor

new BunRouter(maxBodySize?, sslConfig?): BunRouter

Defined in: service-core/src/http/bun/BunRouter.ts:131

Parameters

maxBodySize?

number = DEFAULT_MAX_BODY_SIZE

sslConfig?

any

Returns

BunRouter

Properties

listenPort

listenPort: number = 0

Defined in: service-core/src/http/bun/BunRouter.ts:129

The port the server is currently listening on (set after a successful listen() call).

Implementation of

IHttpRouter.listenPort

Accessors

isListening

Get Signature

get isListening(): boolean

Defined in: service-core/src/http/bun/BunRouter.ts:137

Returns true if the server is currently listening.

Returns

boolean

Implementation of

IHttpRouter.isListening

Methods

close()

close(): void

Defined in: service-core/src/http/bun/BunRouter.ts:454

Stops the server, closing the listen socket.

Returns

void

Implementation of

IHttpRouter.close


delete()

delete(routePath, ...handlers): this

Defined in: service-core/src/http/bun/BunRouter.ts:193

Parameters

routePath

string

handlers

...RequestHandler[]

Returns

this

Implementation of

IHttpRouter.delete


get()

get(routePath, ...handlers): this

Defined in: service-core/src/http/bun/BunRouter.ts:181

Parameters

routePath

string

handlers

...RequestHandler[]

Returns

this

Implementation of

IHttpRouter.get


head(routePath, ...handlers): this

Defined in: service-core/src/http/bun/BunRouter.ts:201

Parameters

routePath

string

handlers

...RequestHandler[]

Returns

this

Implementation of

IHttpRouter.head


listen()

listen(host, port): Promise<void>

Defined in: service-core/src/http/bun/BunRouter.ts:405

Starts listening on the given host and port. Resolves when the server is ready; rejects if the port cannot be bound.

Parameters

host

string

port

number

Returns

Promise<void>

Implementation of

IHttpRouter.listen


options()

options(routePath, ...handlers): this

Defined in: service-core/src/http/bun/BunRouter.ts:205

Parameters

routePath

string

handlers

...RequestHandler[]

Returns

this

Implementation of

IHttpRouter.options


patch()

patch(routePath, ...handlers): this

Defined in: service-core/src/http/bun/BunRouter.ts:197

Parameters

routePath

string

handlers

...RequestHandler[]

Returns

this

Implementation of

IHttpRouter.patch


post()

post(routePath, ...handlers): this

Defined in: service-core/src/http/bun/BunRouter.ts:185

Parameters

routePath

string

handlers

...RequestHandler[]

Returns

this

Implementation of

IHttpRouter.post


put()

put(routePath, ...handlers): this

Defined in: service-core/src/http/bun/BunRouter.ts:189

Parameters

routePath

string

handlers

...RequestHandler[]

Returns

this

Implementation of

IHttpRouter.put


use()

use(...handlers): this

Defined in: service-core/src/http/bun/BunRouter.ts:142

Register global middleware that runs before every route handler.

Parameters

handlers

...RequestHandler[]

Returns

this

Implementation of

IHttpRouter.use


ws()

ws(routePath, handlers, _wsOptions?, upgradeAuth?): this

Defined in: service-core/src/http/bun/BunRouter.ts:219

Registers a WebSocket route. Handlers follow the same (req, res, next) pattern as HTTP routes; they receive req.websocket containing the Bun WebSocket shim.

upgradeAuth is an optional pre-upgrade auth function, run synchronously inside fetch() before the handshake. If it returns { reject: true }, an HTTP 401 is sent and the upgrade is aborted. If it returns { user, ... }, those credentials are attached to the request so downstream middleware sees an authenticated user. If it returns {}, auth falls through to the post-upgrade message-based LOGIN flow.

Parameters

routePath

string

handlers

RequestHandler[]

_wsOptions?

any

upgradeAuth?

WsUpgradeAuth

Returns

this

Implementation of

IHttpRouter.ws