forked from nodenica/nodenica-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.js
87 lines (68 loc) · 2.02 KB
/
web.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
var express = require('express');
var cookieParser = require('cookie-parser');
var session = require('express-session');
var bodyParser = require('body-parser');
var MongoStore = require('connect-mongo')(session);
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io').listen(server);
var lingua = require('lingua');
var raven = require('raven');
var models = require('./models');
var routes = require('./routes');
var config = require('./config');
var helpers = require('./helpers');
// Session store
var store = new MongoStore({
host: config.mongodb.host,
port: config.mongodb.port,
db: config.mongodb.db,
username: config.mongodb.username,
password: config.mongodb.password
});
helpers.socket.setStore( store );
// Process handler
helpers.process.init();
var socketio = new helpers.socket.use( io );
// send data to newrelic
if( helpers.site.isProduction() ){
require('newrelic');
}
// Socket settings
io.set('log level', 1);
io.set('authorization', helpers.socket.authorization);
io.set("transports", ["xhr-polling"]);
io.set("polling duration", 10);
server.listen( config.port );
// set view directory
app.set('views', __dirname + '/views');
// set view engine
app.set('view engine', 'jade');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(cookieParser());
app.use(session({
secret: config.express.secret,
store: store,
key: config.express.key
}));
// Set public directory
app.use(express.static(__dirname + '/public'));
// Set language
app.use(lingua(app, {
defaultLocale: config.lang,
path: __dirname + '/i18n'
}));
// Site middleware
app.use(helpers.site.express);
// socketio middleware
app.use(helpers.socket.express(socketio));
// Validate installation
app.use( helpers.install );
app.use(raven.middleware.express( config.log.url ));
// PID
helpers.pid.make();
// Routes
routes.setup( app );