Skip to content

Documentation / @super-line/server

@super-line/server

The server for super-line — end-to-end typesafe WebSockets for TypeScript. Implements a shared contract over ws: role-keyed handlers, rooms, topics, middleware, lifecycle hooks, and node-to-node messaging.

bash
pnpm add @super-line/core @super-line/server zod
ts
import http from 'node:http'
import { createSocketServer } from '@super-line/server'
import { api } from './contract'

const server = http.createServer()
const srv = createSocketServer(api, {
  server,
  authenticate: (req) => ({ role: 'user' as const, ctx: { id: '1' } }), // throw -> 401
})

srv.implement({
  user: {
    send: async ({ text }, ctx, conn) => {
      conn.emit('message', { text })
      return { id: crypto.randomUUID() }
    },
  },
})

server.listen(3000)

Authenticate returns { role, ctx }; cross-role calls are rejected with NOT_FOUND. Scale across processes with @super-line/adapter-redis.

MIT © Mert

Classes

Interfaces

Type Aliases

Functions

Released under the MIT License.