Skip to content

Instantly share code, notes, and snippets.

@kevinswiber
Last active March 9, 2016 22:17
Show Gist options
  • Save kevinswiber/9c86fbc609ad6c6b4b9a to your computer and use it in GitHub Desktop.
Save kevinswiber/9c86fbc609ad6c6b4b9a to your computer and use it in GitHub Desktop.
Authorization Zetta stream topics in multiplexed event stream.
var zetta = require('zetta');
var Photocell = require('zetta-photocell-mock-driver');
zetta()
.name('kevin-mbp')
.use(Photocell)
.use(function(runtime) {
var broker = runtime.httpServer.eventBroker;
var saved = broker._publishStreamEnabledClient;
broker._publishStreamEnabledClient = function() {
var args = Array.prototype.slice.call(arguments);
var client = args[0];
var data = args[2];
if (client && client.ws && client.ws._isServer
&& client.ws.upgradeReq.url === '/events') {
var headers = client.ws.upgradeReq.headers;
if (headers && headers.authorization && headers.authorization === 'test') {
// check data.topic for topic authorization
saved.apply(broker, args);
} else {
return;
}
} else {
saved.apply(broker, args);
}
};
})
.listen(process.env.PORT || 3004);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment