bitsensor
v0.9.0
Published
BitSensor Node.js Plugin
Downloads
4
Readme
BitSensor Node.js Plugin
Usage
Add bitsensor
to your dependencies.
npm install bitsensor --save
Create a config.json
file.
{
"uri": "http://bitsensor.io/api/",
"user": "your_username",
"apiKey": "your_api_key",
"mode": "on",
"connectionFail": "block",
"ipAddressSrc": "remoteAddr",
"nodeApi": "http" or "hapi"
}
Run BitSensor inside your handleRequest()
method.
var BitSensor = require('bitsensor/core/bitsensor');
var HttpHandler = require('bitsensor/handler/http-handler');
var fs = require('fs');
var http = require('http');
// Start BitSensor with the path of the config.json file as argument
var sensor = new BitSensor(fs.realpathSync('config.json'));
function handleRequest(request, response) {
// Use the handler for http server
sensor.addHandler(new HttpHandler(request, response));
sensor.runHandlers();
sensor.authorize(function () {
// DoYaThing
}, response);
}
var server = http.createServer(handleRequest);
server.listen(8080, function () {
console.log('Server listening on http://localhost:8080');
});