Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f414ae
commit 0b06664
Showing
3 changed files
with
70 additions
and
62 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
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,13 +1,66 @@ | ||
|
||
var geddy = global.geddy || {} | ||
, utils; | ||
, cluster = require('cluster') | ||
, master | ||
, worker | ||
, utils = require('./utils/index') | ||
, fs = require('fs') | ||
, pkg = JSON.parse(fs.readFileSync(__dirname + '/../package.json').toString()) | ||
, App; | ||
|
||
geddy.isMaster = cluster.isMaster; | ||
|
||
utils.mixin(geddy, {version: pkg.version}); | ||
utils.mixin(geddy, utils); | ||
utils.mixin(geddy, new (function () { | ||
var _started = false | ||
, _opts = {}; | ||
|
||
this.config = function (o) { | ||
_opts = o; | ||
}; | ||
|
||
this.start = function () { | ||
var m | ||
, w | ||
, app; | ||
|
||
// No repeatsies | ||
if (_started) { | ||
return; | ||
} | ||
|
||
// Master-process, start workers | ||
if (geddy.isMaster) { | ||
master = require('../lib/cluster/master') | ||
m = new master.Master(); | ||
m.start(_opts); | ||
} | ||
// Worker-process, start up an app | ||
else { | ||
App = require('./app.js').App; | ||
|
||
worker = require('../lib/cluster/worker') | ||
w = new worker.Worker(); | ||
geddy.worker = w; | ||
|
||
w.init(function () { | ||
utils.mixin(geddy, w); | ||
|
||
app = new App(); | ||
app.init(function () { | ||
w.startServer(); | ||
utils.mixin(geddy, app); | ||
}); | ||
}); | ||
} | ||
}; | ||
|
||
})()); | ||
|
||
// Set the One True Geddy Global | ||
global.geddy = geddy; | ||
utils = require('./utils/index'); | ||
// Hang all the util namespaces on the global geddy | ||
for (var p in utils) { | ||
geddy[p] = utils[p]; | ||
} | ||
// Could also be used as export/local | ||
|
||
// Also allow export/local | ||
module.exports = geddy; | ||
|
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