Gateways
A Gateway is the WebSocket counterpart to a Router. Where a Router exposes HTTP endpoints, a Gateway exposes Socket.io namespace event handlers, with the same building blocks you already use across Arkos: validation, authentication, authorization, and interceptor-style middlewares.
import { ArkosGateway } from "arkos/websockets";
const chatGateway = ArkosGateway({
name: "chat",
authentication: true,
});
chatGateway.on({ event: "send_message" }, (socket, data) => {
socket.to(data.room).emit("receive_message", data);
});
export default chatGateway;A Gateway is created with ArkosGateway(config) and wired into a socket.io Server with .register(io). Everything else — defining events, socket enhancements, pipes, hooks, deduplication — lives under WebSockets.
Anatomy
| Piece | Purpose |
|---|---|
config.name | Socket.io namespace. Defaults to "web-socket". |
.on() | Registers an event handler. |
.use() | Registers connection middleware or composes a child Gateway. |
.pipe() | Registers event-level middleware. |
.hook() | Registers a connection, disconnect, or error lifecycle handler. |
.register(io) | Mounts the Gateway (and any nested Gateways) onto a Socket.io server. |
Where it lives
Gateways don't get auto-discovered like Routers do off your Prisma models — you define and register them explicitly, same as a custom Router:
// src/app.ts
import { Server } from "socket.io";
import chatGateway from "./gateways/chat.gateway";
const io = new Server(httpServer);
chatGateway.register(io);See WebSockets → Setup for the full registration flow, including plugging in a custom store for rate limiting and deduplication.