Created
January 5, 2016 19:47
-
-
Save trygve-lie/dbfee0d0886dde532b01 to your computer and use it in GitHub Desktop.
Numbat - Example of verifying clients connecting on websockets
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 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' } | |
] | |
}; |
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 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