Skip to content

Instantly share code, notes, and snippets.

@trygve-lie
Created January 5, 2016 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trygve-lie/dbfee0d0886dde532b01 to your computer and use it in GitHub Desktop.
Save trygve-lie/dbfee0d0886dde532b01 to your computer and use it in GitHub Desktop.
Numbat - Example of verifying clients connecting on websockets
var url = require('url');
// our secret which each client will verify against
const SECRET = 'foobar';
module.exports =
{
logging:
{
name: 'numbat-1',
silent: false
},
listen: { host: 'localhost', port: 3333, ws: true, verifyClient: function(info, cb) {
// parse the url and get the key query value
var uri = url.parse(info.req.url, true);
if (uri.query.key === SECRET) {
// key equals our secret, grant client access
cb(true);
} else {
// key does not equal our secret, deny access with a reason
cb(false, 403, 'access denied');
}
} },
outputs:
[
{ type: 'prettylog', name: 'foobar' }
]
};
var Emitter = require('numbat-emitter');
// connect to the collector with a key and a legal secret value
var emitter = new Emitter({
uri: 'ws://localhost:3333/?key=foobar',
app: 'example-1'
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment