index.js | |
---|---|
/*
* index.js: Top-level include for the drone module.
*
* (C) 2010, Nodejitsu Inc.
*
*/
var path = require('path'),
hookio = require('hook.io'),
haibu = require('../../haibu'); | |
Include ExportsExport other components in the module | exports.createRouter = require('./service').createRouter;
exports.Drone = require('./drone').Drone;
exports.Client = require('./client').Client;
exports.started = false; |
function createServer (options)@options {Object} Options to use when creating this serverCreates a server for the haibu | exports.createServer = function (options) {
var drone = new haibu.drone.Drone(options),
router = haibu.drone.createRouter(drone),
contentTypes = { 'application/json': router },
server = haibu.utils.createServer(contentTypes, false, options.port);
server.drone = drone;
return server;
}; |
function startHook (options, callback)@options {Object} Options for the
| exports.startHook = function (options, callback) {
if (!callback && typeof options === 'function') {
callback = options;
options = null;
}
options = options || { name: 'haibu' };
var hook = new hookio.Hook(options);
hook.listen(function (err) {
haibu.running.hook = hook;
return err ? callback(err) : callback(null, hook);
});
}; |
function start (options, callback)@options {Object} Options to use when starting this module.@callback {function} Continuation to respond to when complete.Starts the haibu | exports.start = function (options, callback) {
if (exports.started) {
return callback(null, haibu.running.server);
}
function startServer (err, hook) {
if (err) {
return callback(err);
}
|
Create the server and add the new | var server = exports.createServer(options);
haibu.running.server = server;
haibu.running.drone = server.drone;
haibu.running.ports = {};
return callback(null, server);
}
function startHook (err) {
return err
? callback(err)
: exports.startHook(options.hook, startServer);
} |
Indicate that | exports.started = true;
return options.init !== false
? haibu.init(options, startHook)
: startHook();
};
|