Skip to content

Commit

Permalink
[refactor]: Station now extends Hook. Added default config.json data.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marak committed Jul 5, 2011
1 parent 9bc8be2 commit 894fa7b
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 57 deletions.
17 changes: 15 additions & 2 deletions bin/station
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
var station = require('../lib/station');
station.start();
var Station = require('../lib/station').Station;

var station = new Station({
name: "station",
options: {
"port": 9000,
"basicAuth" : {
"username": "admin",
"password": "admin"
}
}
});

station.start();

46 changes: 45 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1 +1,45 @@
{}
{
"sites": [
{
"name": "Blog",
"url": "http://blog.nodejitsu.com/",
"attempts": 4927,
"pongs": 4877,
"requestTime": 913,
"err": null,
"statusCode": 200
},
{
"name": "Home Page",
"url": "http://www.nodejitsu.com/",
"attempts": 4927,
"pongs": 4881,
"requestTime": 612,
"err": null,
"statusCode": 200
},
{
"name": "Master API",
"url": "http://api.nodejitsu.com/",
"attempts": 4927,
"pongs": 4887,
"requestTime": 413,
"err": null,
"statusCode": 400
},
{
"name": "Local Test",
"url": "http://localhost:8080/",
"attempts": 2776,
"pongs": 2769,
"requestTime": 48,
"err": {
"stack": "Error: ECONNREFUSED, Connection refused\n at Socket._onConnect (net.js:599:18)\n at IOWatcher.onWritable [as callback] (net.js:186:12)",
"message": "ECONNREFUSED, Connection refused",
"errno": 61,
"code": "ECONNREFUSED",
"syscall": "connect"
}
}
]
}
98 changes: 44 additions & 54 deletions lib/station.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,60 @@
var station = exports,
colors = require('colors');

var Webserver = require('hook.io-webserver').Webserver,
http = require('http'),
util = require('util');


station.start = function(){
var Station = exports.Station = function(options){

//
// Require some hooks
// Hook setup
//

for (var o in options) {
this[o] = options[o];
}

Webserver.call(this);

var self = this;

self.use('file', { file: './config.json'});


self.on('ready', function(){

//
// Add some startup commands here
//

self._start();

});

};

// Station inherits from Hook Webserver
util.inherits(Station, Webserver);

Station.prototype._start = function(){

var self = this;

//
// Webserver is used to create a basic webserver
// for listening to real-time events from hook.io in the browser
// Require some hooks
//

var Webserver = require('hook.io-webserver').Webserver;
var webserver = new Webserver({
name: "station",
options: {
"port": 9000,
"basicAuth" : {
"username": "admin",
"password": "admin"
}
}
self.spawn(['pinger', 'webhook'], function(){

});

webserver.on('ready', function(){
console.log('http web server started on port 9000');
/*
var TwiloHook = require('hook.io-twilio').TwiloHook;
var myhook = new TwiloHook( { name: "twillo-hook" } );
myhook.connect();
*/

//
// Webhook is used to create a simple POST / Recieve HTTP Server
// These messages are then piped out
//

var Webhook = require('hook.io-webhook').Webhook;
var webhookServer = new Webhook({
name: "webhook-server",
options: {
"port": 9001,
"debug": true
}
});

// Put some event handlers on your hooks
webhookServer.on('i.*', function(){
console.log('webhookserver in');
});

webhookServer.on('o.*', function(){
console.log('webhookserver out');
});

webhookServer.on('ready', function(){
console.log('station starting!'.green + ' ' + webhookServer.options.port);
});

// Starts up both a hook.io output server, but also an HTTP webhook server listening on webhookServer.options.port
webhookServer.connect();


});

webserver.listen();

};


};

0 comments on commit 894fa7b

Please sign in to comment.