Skip to content

toNodeHandler

View as Markdown
function toNodeHandler(h): UncageNodeHandler;

Defined in: hub/src/node/node-handler.ts:29

The hub as a Node (req, res, next?) middleware for Express, Connect, Fastify (reply.hijack() then handler(request.raw, reply.raw)) and node:http:

app.use(toNodeHandler(hub)); // or app.use(‘/api/uncage’, toNodeHandler(hub)) attachWebSocket(hub, server); // machine WebSockets on the same HTTP server

Only requests under hub.basePath are handled; anything else goes to next() untouched (with no next, e.g. plain node:http, it gets a 404). Paths are read from req.originalUrl (Express) or req.url, so mounting under the prefix works too. Mount before body parsers. The client IP for rate limits is Express’s req.ip (set app.set('trust proxy', …) behind a proxy), else the socket address.

Parameter Type
h Hub

UncageNodeHandler