SecureSocketServer
HTTPS + WebSocket pairing. Mirrors `SocketServer` but wraps an HTTPS server built from the provided TLS files.
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 when Redweb directly owns a TLS WebSocket listener rather than sharing an externally terminated HTTPS connection.
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.
const { SecureSocketServer } = require('redweb')
const { GameRoute } = require('./routes/GameRoute')
new SecureSocketServer({
port: 3443,
ssl: { key: './certs/dev.key', cert: './certs/dev.crt' },
routes: [GameRoute],
})- 1
TLS material is loaded to create or configure the HTTPS listener.
- 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
- 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, services, and the HTTPS listener.