SecureSocketServer
HTTPS + WebSocket pairing. Mirrors `SocketServer`, creating an owned HTTPS server from TLS files or attaching to a supplied HTTPS server.
The simple mental model
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 pattern explains the named API. Application classes, credentials, and assets may need to be supplied; use a complete recipe for a runnable starting point.
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],
})- 1
TLS material is loaded when creating an owned listener; a supplied HTTPS server already owns its TLS configuration and needs no ssl file options.
- 2
WebSocket upgrades travel through the same route selection used by SocketServer.
- 3
Route handlers see ordinary Redweb sockets after the secure handshake completes.
Choices you can make
- 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.