This repository has been archived by the owner on May 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathapp.js
74 lines (62 loc) · 1.97 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
/**
* Author: krasu
* Date: 7/29/13
* Time: 9:14 PM
*/
var http = require('http'),
path = require('path'),
express = require('express'),
cfg = require('./config'),
logger = require('./app/utils/logger'),
MongoStore = require('connect-mongo')(express),
mongoose = require('mongoose'),
app = express();
mongoose.connect(cfg.mongodbUri)
mongoose.connection.on('error', function (err) {
logger.error('Mongo connection error', err.message);
});
mongoose.connection.once('open', function callback () {
logger.info("Connected to MongoDB");
});
// Bootstrap models
require('./app/models')
var passport = require('./app/middleware/passport')
var sessionStore = new MongoStore({
url: cfg.mongodbUri
})
app.locals._ = require('lodash');
app.locals.titleBuilder = require('./app/utils/title-builder');
app.locals.jsPath = cfg.jsPath;
app.locals.siteUrl = cfg.fullUrl();
// all environments
app.set('port', cfg.port);
app.set('views', __dirname + '/app/views');
app.set('view engine', 'ejs');
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.logger('dev'));
app.use(express.favicon(path.join(__dirname, 'public/favicon.ico')));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser(cfg.sessionSecret));
app.use(express.session({
secret: cfg.sessionSecret,
store: sessionStore
}));
app.use(passport.initialize());
app.use(passport.session());
require('./app/middleware/users')(app)
app.use(app.router);
require('./app/routes')(app)
if (cfg.isDev) {
app.use(express.errorHandler());
} else {
require('./app/middleware/errors')(app)
}
var server = http.createServer(app)
require('./app/utils/socket.io')(server, sessionStore)
require('./app/utils/mailer').fillTemplates(path.join(__dirname, 'app/views/emails/'), function (error) {
if (error) throw error;
server.listen(app.get('port'), function () {
logger.info('Express server listening on port ' + app.get('port'));
});
})