Skip to content

Documentation / @super-line/server / createSuperLineServer

Function: createSuperLineServer() ​

createSuperLineServer<C, A, P>(contract, opts): SuperLineServer<C, A, PluginHandledKeys<P[number]>>

Defined in: index.ts:694

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

P ​

P extends readonly SuperLinePlugin<any>[] = []

Parameters ​

contract ​

C

the shared contract.

opts ​

SuperLineServerOptions<C, A, P>

server options; authenticate is required.

Returns ​

SuperLineServer<C, A, PluginHandledKeys<P[number]>>

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: '...' }) },
})

Released under the MIT License.