-
Notifications
You must be signed in to change notification settings - Fork 39
/
app.js
52 lines (43 loc) · 1.38 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
/**
* Module dependencies.
*/
var express = require('express')
, http = require('http')
, path = require('path')
, partials = require('express-partials')
, underscore = require('underscore')
, config = require('./config')
, app = express();
// set config by environment
if (process.env.ENVIRONMENT!='default') {
app.config = underscore.extend(config.default, config[process.env.ENVIRONMENT]);
} else {
app.config = config.default;
}
// setup socket io
global.io = require('socket.io').listen(app.listen( app.config.server.port ));
io.sockets.on('connection', function (socket) {
// @TODO: Implement setting of max threads
socket.on('setMaxThreads', function (data) {});
});
// db connect
var db = require('mongoose');
db.connect(app.config.db.service+'://'+app.config.db.host+'/'+app.config.db.database);
app.configure(function() {
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.set('view options', { layout: true, pretty: true });
app.set('config', app.config);
app.set('db', db);
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(partials());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
});
app.configure('development', function(){
app.use(express.errorHandler());
});
require('./routes')(app);