Files

11 lines
822 B
JavaScript
Raw Permalink Normal View History

// Swappable pub/sub for cross-instance real-time fan-out. The app delivers to its OWN WebSocket clients
// locally (chat.js) exactly as before; this layer only carries a copy to OTHER app instances so a message
// POSTed on instance A reaches a recipient whose socket lives on instance B.
//
// Backend chosen by PUBSUB_BACKEND (default 'memory'). 'memory' = single instance: publish is a no-op and
// subscriptions never fire, so behaviour is identical to before this layer existed — zero hot-path cost.
// 'redis' fans out via Redis. The interface (publish/subscribe/init) is deliberately tiny so Redis is one
// swappable file — a Postgres LISTEN/NOTIFY or NATS backend could drop in the same way. Never hardwired.
const name = process.env.PUBSUB_BACKEND || 'memory';
module.exports = require('./pubsub/' + name);