forked from impronunciable/hackdash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
105 lines (84 loc) · 2.19 KB
/
server.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* Module dependencies.
*/
var express = require('express')
, passport = require('passport')
, mongoose = require('mongoose')
, MongoStore = require('connect-mongo')(express)
, config = require('./config.json')
, http = require('http');
/*
* DB
*/
mongoose.connect(config.db.url || ('mongodb://' + config.db.host + '/'+ config.db.name));
var app = exports.app = express();
/*
* Application config
*/
app.configure(function(){
app.set('config', config);
app.set('port', process.env.PORT || app.get('config').port);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon(__dirname + '/public/favicon.ico'));
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.limit('3.5mb'));
app.use(express.methodOverride());
app.use(express.cookieParser(app.get('config').session));
app.use(express.session({
secret: app.get('config').session
, store: new MongoStore({db: app.get('config').db.name, url:
app.get('config').db.url})
, cookie: { maxAge: 365 * 24 * 60 * 60 * 1000, path: '/', domain: '.' + app.get('config').host }
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
app.use(function(req, res) {
res.status(400);
res.render('404');
});
app.use(function(error, req, res, next) {
console.log(error);
res.status(500);
res.render('500');
});
app.set('statuses',['brainstorming','wireframing','building','researching','prototyping','releasing']);
app.locals.title = config.title;
});
app.configure('development', function(){
app.use(express.errorHandler());
});
/*
* Models
*/
require('./models')(app);
/*
* Auth
*/
require('./auth')(app);
/*
* Routes
*/
require('./routes')(app);
/*
* Mailer
*/
if(app.get('config').mailer) {
require('./mailer')(app);
}
var server = module.exports = http.Server(app);
/*
* Live dashboard
*/
if(config.live) {
require('./live')(app, server);
}
server.listen(app.get('port'), function() {
console.log("Express server listening on port " + app.get('port'));
});
process.on('uncaughtException', function(err){
console.log(err);
});