-
Notifications
You must be signed in to change notification settings - Fork 87
/
server.js
73 lines (58 loc) · 1.85 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
'use strict';
// Module dependencies.
var express = require('express'),
http = require('http'),
passport = require('passport'),
path = require('path'),
fs = require('fs'),
mongoStore = require('connect-mongo')(express),
config = require('./lib/config/config');
var app = express();
// Connect to database
var db = require('./lib/db/mongo').db;
// Bootstrap models
var modelsPath = path.join(__dirname, 'lib/models');
fs.readdirSync(modelsPath).forEach(function (file) {
require(modelsPath + '/' + file);
});
var pass = require('./lib/config/pass');
// App Configuration
app.configure('development', function(){
app.use(express.static(path.join(__dirname, '.tmp')));
app.use(express.static(path.join(__dirname, 'app')));
app.use(express.errorHandler());
app.set('views', __dirname + '/app/views');
});
app.configure('production', function(){
app.use(express.favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(express.static(path.join(__dirname, 'public')));
app.set('views', __dirname + '/views');
});
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
app.use(express.logger('dev'));
// cookieParser should be above session
app.use(express.cookieParser());
// bodyParser should be above methodOverride
app.use(express.bodyParser());
app.use(express.methodOverride());
// express/mongo session storage
app.use(express.session({
secret: 'MEAN',
store: new mongoStore({
url: config.db,
collection: 'sessions'
})
}));
// use passport session
app.use(passport.initialize());
app.use(passport.session());
//routes should be at the last
app.use(app.router);
//Bootstrap routes
require('./lib/config/routes')(app);
// Start server
var port = process.env.PORT || 3000;
app.listen(port, function () {
console.log('Express server listening on port %d in %s mode', port, app.get('env'));
});