Documentation / @super-line/server / createSuperLineServer
Function: createSuperLineServer()
createSuperLineServer<
C,A>(contract,opts):SuperLineServer<C,A>
Defined in: index.ts:356
Create a server bound to a contract. Attach it to an http.Server, then call SuperLineServer.implement with your handlers. authenticate resolves each connection's { role, ctx } at the upgrade.
Type Parameters
C
C extends Contract
A
A extends object
Parameters
contract
C
the shared contract.
opts
SuperLineServerOptions<C, A>
server options; authenticate is required.
Returns
SuperLineServer<C, A>
the SuperLineServer.
Throws
nothing directly; handler throws become a typed SuperLineError to the client.
Example
ts
const srv = createSuperLineServer(api, {
transports: [webSocketServerTransport({ server })],
authenticate: (h) => ({ role: 'user' as const, ctx: { id: '1' } }),
})
srv.implement({
shared: { join: async ({ room }, _ctx, conn) => { srv.room(room).add(conn); return { ok: true } } },
user: { say: async ({ text }, ctx) => ({ id: '...' }) },
})