UNPKG

rocky

Version:

Full-featured, middleware-oriented, hackable HTTP and WebSocket proxy

28 lines (21 loc) 764 B
const passes = require('./passes') const clone = require('lodash').clone module.exports = Dispatcher function Dispatcher (rocky) { this.rocky = rocky } Dispatcher.prototype.dispatch = function (req, socket, head, done) { const rocky = this.rocky // Dispatch WebSocket middleware rocky.mw.run('ws', req, socket, head, function dispatcher (err) { if (err) return done(err) this.doDispatch(req, socket, head, done) }.bind(this)) } Dispatcher.prototype.doDispatch = function (req, socket, head, done) { const opts = clone(this.rocky.opts) this.dispatchConcurrently(opts, req, socket, head, done) } Dispatcher.prototype.dispatchConcurrently = function (opts, req, socket, head, done) { passes.concurrently(opts, req, socket, head, done) }