-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[refactor]: Station now extends Hook. Added default config.json data.
- Loading branch information
Showing
3 changed files
with
104 additions
and
57 deletions.
There are no files selected for viewing
This file contains 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
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(); | ||
|
This file contains 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
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" | ||
} | ||
} | ||
] | ||
} |
This file contains 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
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(); | ||
|
||
}; | ||
|
||
|
||
}; |