-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
53 lines (36 loc) · 1.57 KB
/
server.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
53
'use strict';
const koa = require('koa'),
app = koa();
app.base = __dirname;
require('colors'); // PRETTY CONSOLE LOGGING
require('fs'); // FILE SYSTEM
require(__dirname + '/config/_settings')(app); // MAIN APP SETTINGS
process.env.NODE_ENV = process.env.NODE_ENV || 'development'; // SET DEFAULT ENVIRONMENT
let gabba = app.gabba = require('./lib/gabba')(app); // INCLUDE POG LIB
app.log = gabba.log;
gabba.inform(app, 'start'); // START UP MESSAGE
// REQUIRED SETTINGS & CONFIG FILES
require(__dirname + '/config/environment/' + process.env.NODE_ENV)(app); // ENVIRONMENT SPECIFIC SETTINGS
require(__dirname + '/config/server')(app, gabba); // VIEW SETTINGS
app.gabba = gabba; // ADD POG OBJECT TO APP
var base = require('path').resolve(__dirname, '../../'),
config = require( __dirname + '/app/models/config')( app ),
Waterline = require('waterline'),
orm = new Waterline();
orm.loadCollection(require( __dirname + '/app/models/user.js')(app).init());
orm.loadCollection(require( __dirname + '/app/models/message.js')(app).init());
orm.initialize(config, function(err, models) {
app.models = models.collections;
app.connections = models.connections;
// START THE APP BY LISTENING ON <PORT>
app.server = app.listen( process.env.PORT || app.config.port, function( err ) {
if ( !err ) { // IF THERE'S NO ERRORS
// ENABLE SOCKET.IO
require('./app/sockets')(app);
// TELL EVRYTHING IS GOOD TO GO
gabba.inform(app, 'done');
} else { // IF SOMETHING WENT WRONG!
gabba.inform(app, 'error', err);
}
});
});