SecureSocketServer
Documentation for Redweb 0.16.1. Install that exact version when following these examples.
HTTPS + WebSocket pairing. Mirrors SocketServer, creating an owned HTTPS server from TLS files or attaching to a supplied HTTPS server.
Explain it like I’m five
SecureSocketServer is the encrypted version of the WebSocket switchboard: clients use wss:// and the connection stays protected from the first handshake onward.
When should I use it?
Use it to own a TLS WebSocket listener or share an existing Node HTTPS server.
Follow the example
This API pattern illustrates the named surface; it may require application-owned classes, credentials, or assets. Start from a complete recipe for a runnable application.
import { SecureSocketServer } from 'redweb'
import { GameRoute } from './routes/GameRoute.js'
new SecureSocketServer({
port: 3443,
ssl: { key: './certs/dev.key', cert: './certs/dev.crt' },
routes: [GameRoute],
})- TLS material is loaded when creating an owned listener; a supplied HTTPS server already owns its TLS configuration and needs no ssl file options.
- WebSocket upgrades travel through the same route selection used by SocketServer.
- Route handlers see ordinary Redweb sockets after the secure handshake completes.
Options
- port: number (default 3000)
- listen: boolean (default true for owned servers); supplied servers do not listen unless explicitly true
- server: existing https.Server to attach to without double-listening (optional)
- ssl.key and ssl.cert: required file paths only when creating an owned HTTPS server
- closeServerOnShutdown: defaults to true for owned servers and false for supplied servers
- routes: array of SocketRoute subclasses
Methods and members
constructor(options)
Loads TLS files or reuses a supplied HTTPS server, registers the provided routes, attaches upgrade handling, and starts listening only when Redweb owns the server or listen is explicitly true.
addRoute(RouteClass)
Same runtime route attachment as SocketServer.
shutdown()
Stops routes and services. Closes the HTTPS listener only when owned or closeServerOnShutdown is explicitly true; supplied servers remain open by default.
What should I watch for?
Supplied HTTPS servers remain open after shutdown by default; their owner controls listening and final cleanup. Do not duplicate TLS termination accidentally: behind a TLS-terminating proxy, use SocketServer and configure trusted origins.