-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
52 lines (42 loc) · 1.49 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env node
var argv = require('optimist').argv;
require('coffee-script')
var util = require("util");
var Cell = require("organic-webcell/WebCell");
var DNA = require("organic").DNA;
var mongoose = require('mongoose');
var mongojs = require("mongojs");
var modelBase = require("./api/models/Base");
process.env.CELL_MODE = process.env.NODE_ENV || process.env.CELL_MODE || "development";
module.exports = function(callback) {
console.log(("api running in CELL_MODE == "+process.env.CELL_MODE).blue);
var self = this;
var bootApp = function(){
var db = mongoose.createConnection('localhost', dna.plasma.ExpressHttpActions.mongo.dbname);
db.once("open", function(){
modelBase.db = db;
Cell.call(self, dna, callback);
self.plasma.on("WebSocketServer", function(c){
modelBase.io = c.data.server;
});
});
}
var dna = new DNA();
dna.loadDir(process.cwd()+"/dna", function(){
if(dna[process.env.CELL_MODE])
dna.mergeBranchInRoot(process.env.CELL_MODE);
if(process.env.CELL_MODE == "test" || argv.cleanDB) {
var connection = mongojs.connect(dna.plasma.ExpressHttpActions.mongo.dbname)
connection.dropDatabase(function(){
console.log((dna.plasma.ExpressHttpActions.mongo.dbname+" is dropped").red);
connection.close();
bootApp();
});
} else
bootApp();
});
}
util.inherits(module.exports, Cell);
// start the cell if this file is not required
if(!module.parent)
new module.exports();