-
Notifications
You must be signed in to change notification settings - Fork 20
/
app.js
86 lines (75 loc) · 2.57 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// dependencies
var http = require('http');
var mongoose = require('mongoose');
var session = require('express-session');
var RedisStore = require('connect-redis')(session);
var cookieParser = require('cookie-parser');
var handlebars = require('hbs');
var passport = require('passport');
var socketio = require('socket.io')();
// config and setup helpers
var helpers = require('helpers');
var config = require('config');
var setup = require('./setup');
// setup session store
var sessionStore = setup.sessions({
cookieParser: cookieParser,
env: config.get('env'),
Store: RedisStore,
session: session,
url: config.get('database.redis.url'),
prefix: config.get('database.redis.session.prefix'),
db: config.get('database.redis.db'),
secret: config.get('server.secret')
});
// create/configure express app
var app = setup.createExpressApp({
passport: passport,
handlebars: handlebars,
cookieParser: cookieParser,
session: session,
store: sessionStore,
sessionKey: config.get('session.key'),
sessionSecret: config.get('server.secret'),
dir: __dirname,
static: '/client/public',
favicon: '/client/public/images/favicon.ico',
views: '/views',
env: config.get('env')
});
// mail module
var mailer = require('modules/mailer')({
env: config.get('env'),
serviceName: config.get('service.name'),
apiKey: config.get('mandrill.api.key'),
senderAddress: config.get('mandrill.sender'),
verificationRoute: config.get('email.verification.route')
});
// http and socket.io server(s)
var server = http.createServer(app);
var io = socketio.attach(server);
// app dependencies (app specific)
var ipc = require('modules/ipc')(0);
var models = require('./models')(mongoose);
var services = require('./services')(models);
var handlers = require('./handlers')(passport, services);
var authentication = require('modules/authentication')(models, mailer);
// setup application
setup.connectToDatabase(mongoose, config.get('database.mongo.url'));
setup.registerPartials('./views/partials/', handlebars);
setup.registerHelpers(helpers.handlebars, handlebars);
// configure socket.io
setup.configureSockets(io, {
cookieParser: cookieParser,
sessionStore: sessionStore,
sessionKey: config.get('session.key'),
sessionSecret: config.get('server.secret'),
});
// app specific modules
require('modules/sockets')(io, ipc);
require('modules/passport')(passport, authentication, models);
require('./routes')(app, handlers);
// express error handling
setup.handleExpressError(app);
// run application
setup.run(server, config.get('server.port'));