1. HTTP and WebSockets on one listener
Build the Express side without binding, attach route classes to the same Node server, then listen once. Redweb leaves the server visible and caller-owned.
const { HttpServer, METHODS, SocketServer } = require('redweb')
const http = new HttpServer({
port: 3030,
listen: false,
publicPaths: ['./public'],
services: [{
serviceName: '/health',
method: METHODS.GET,
function: (_request, response) => response.json({ ok: true }),
}],
})
const sockets = new SocketServer({
server: http.server,
routes: [ChatRoute, PresenceRoute],
})
http.server.listen(3030)
process.once('SIGTERM', async () => {
await sockets.shutdown()
await http.shutdown()
})- Static files and JSON APIs share the Express app.
- WebSocket upgrades are routed by path.
- Await both shutdown helpers when the process exits.