Skip to main content

Interface: HttpRouter

Defined in: service-core/src/http/uWS/Router.ts:191

Thin Express-compatible wrapper over uWS.TemplatedApp.

Provides the same app.get(), app.post(), app.use(), etc. API that RouteUtils.registerRoute() uses, so no changes are needed in route registration code. Global middleware registered via use() is prepended to every route's chain.

Also supports:

  • ws(path, handlers) — native uWS WebSocket routing
  • listen(host, port) / close() — server lifecycle

Implements​

Indexable​

[key: string]: any

Properties​

listenPort​

listenPort: number = 0

Defined in: service-core/src/http/uWS/Router.ts:201

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

Implementation of​

IHttpRouter.listenPort

Accessors​

inFlightRequests​

Get Signature​

get inFlightRequests(): number

Defined in: service-core/src/http/uWS/Router.ts:531

The number of HTTP requests currently being handled.

Returns​

number


isListening​

Get Signature​

get isListening(): boolean

Defined in: service-core/src/http/uWS/Router.ts:226

Returns true if the server is currently listening.

Returns​

boolean

Implementation of​

IHttpRouter.isListening

Methods​

close()​

close(): void

Defined in: service-core/src/http/uWS/Router.ts:523

Closes the listen socket, stopping the server from accepting new connections.

Returns​

void

Implementation of​

IHttpRouter.close


delete()​

delete(routePath, ...handlersOrOptions): this

Defined in: service-core/src/http/uWS/Router.ts:295

Parameters​

routePath​

string

handlersOrOptions​

...(HttpRouteOptions | RequestHandler)[]

Returns​

this

Implementation of​

IHttpRouter.delete


get()​

get(routePath, ...handlersOrOptions): this

Defined in: service-core/src/http/uWS/Router.ts:271

Parameters​

routePath​

string

handlersOrOptions​

...(HttpRouteOptions | RequestHandler)[]

Returns​

this

Implementation of​

IHttpRouter.get


hasExplicitOptionsRoute()​

hasExplicitOptionsRoute(path): boolean

Defined in: service-core/src/http/uWS/Router.ts:337

Returns true if the application has registered its own literal OPTIONS route at path (not the framework's own /* CORS-preflight fallback). See explicitOptionsPaths's own doc comment. path is normalized the same way registered routes are, so a trailing-slash mismatch between the two doesn't cause a false miss. Only exact literal paths are tracked - a :param-containing OPTIONS route is not matched here, since that would require reimplementing uWS's own path-pattern matching.

Parameters​

path​

string

Returns​

boolean

Implementation of​

IHttpRouter.hasExplicitOptionsRoute


head(routePath, ...handlersOrOptions): this

Defined in: service-core/src/http/uWS/Router.ts:311

Parameters​

routePath​

string

handlersOrOptions​

...(HttpRouteOptions | RequestHandler)[]

Returns​

this

Implementation of​

IHttpRouter.head


listen()​

listen(host, port): Promise<void>

Defined in: service-core/src/http/uWS/Router.ts:482

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, ...handlersOrOptions): this

Defined in: service-core/src/http/uWS/Router.ts:320

Parameters​

routePath​

string

handlersOrOptions​

...(HttpRouteOptions | RequestHandler)[]

Returns​

this

Implementation of​

IHttpRouter.options


patch()​

patch(routePath, ...handlersOrOptions): this

Defined in: service-core/src/http/uWS/Router.ts:303

Parameters​

routePath​

string

handlersOrOptions​

...(HttpRouteOptions | RequestHandler)[]

Returns​

this

Implementation of​

IHttpRouter.patch


post()​

post(routePath, ...handlersOrOptions): this

Defined in: service-core/src/http/uWS/Router.ts:279

Parameters​

routePath​

string

handlersOrOptions​

...(HttpRouteOptions | RequestHandler)[]

Returns​

this

Implementation of​

IHttpRouter.post


put()​

put(routePath, ...handlersOrOptions): this

Defined in: service-core/src/http/uWS/Router.ts:287

Parameters​

routePath​

string

handlersOrOptions​

...(HttpRouteOptions | RequestHandler)[]

Returns​

this

Implementation of​

IHttpRouter.put


shutdown()​

shutdown(timeoutMs?): Promise<void>

Defined in: service-core/src/http/uWS/Router.ts:541

Stops accepting new connections, waits up to timeoutMs for in-flight HTTP requests to finish, then closes every remaining connection (keep-alive and WebSocket connections included).

Parameters​

timeoutMs?​

number = 10000

The maximum time to wait for in-flight requests, in milliseconds.

Returns​

Promise<void>

Implementation of​

IHttpRouter.shutdown


use()​

use(...handlers): this

Defined in: service-core/src/http/uWS/Router.ts:231

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/uWS/Router.ts:353

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

upgradeAuth is an optional pre-upgrade auth function. When provided it runs synchronously inside the uWS upgrade callback 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.

Both path and path + "/" are registered to avoid trailing-slash mismatch.

Parameters​

routePath​

string

handlers​

RequestHandler[]

wsOptions?​

WebSocketOptions | Partial<WebSocketBehavior<any>>

upgradeAuth?​

WsUpgradeAuth

Returns​

this

Implementation of​

IHttpRouter.ws