Last active
March 9, 2016 22:17
-
-
Save kevinswiber/9c86fbc609ad6c6b4b9a to your computer and use it in GitHub Desktop.
Authorization Zetta stream topics in multiplexed event stream.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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