-
Notifications
You must be signed in to change notification settings - Fork 23
/
app.js
62 lines (49 loc) · 1.54 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
53
54
55
56
57
58
59
60
61
62
'use strict';
var config = require('./config');
if (config.newrelic.license_key) {
require('newrelic');
}
var express = require('express');
var http = require('http');
var path = require('path');
var io = require('socket.io');
var logger = require('morgan');
var bodyParser = require('body-parser');
var errorHandler = require('errorhandler');
var db = require('./db');
var analytics = require('./analytics');
var indexRoute = require('./routes/index');
var roomsRoute = require('./routes/rooms');
var app = express();
var server = http.createServer(app);
app.set('port', config.express.port);
app.set('views', path.join(__dirname, '/views'));
app.set('view engine', 'jade');
app.use(logger('dev'));
app.use(bodyParser.json({ limit: config.express.request_limit }));
app.use(express.static(path.join(__dirname, 'public'), {
maxAge: 2678400000, // one month
}));
if (config.env == 'development') {
app.use(errorHandler());
app.use(function(req, res, next) {
res.locals.isDev = true;
next();
});
} else {
if (analytics.trackingId) {
console.log('Google Analytics enabled on', analytics.trackingId);
app.use(analytics.middleware(analytics.trackingId));
}
}
app.use('/', indexRoute);
db.connect(config.mongodb.uri, function(err) {
if (err) {
console.log('Unable to connect to Mongo.');
process.exit(1);
}
server.listen(app.get('port'), config.express.host);
io = io.listen(server);
app.use('/r', roomsRoute('/r', io));
console.log('Listening on http://' + (app.get('host') || 'localhost') + ':' + app.get('port'));
});