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 zodts
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.
- 📖 Docs: https://mertdogar.github.io/super-line/
- 📚 Guides: roles & auth, events & rooms
- 📕 API reference: https://mertdogar.github.io/super-line/reference/
- 🧩 Source: https://github.com/mertdogar/super-line
MIT © Mert
Classes
Interfaces
- Backpressure
- ClusterView
- ConnTarget
- LocalView
- MiddlewareInfo
- RoleLens
- Room
- ServerOptions
- SocketServer
- UserTarget