-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
72 lines (60 loc) · 1.97 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
var express = require('express'),
io = require('socket.io'),
app = express(),
http = require('http'),
passport = require('passport'),
path = require('path'),
fs = require('fs'),
favicon = require('serve-favicon'),
logger = require('morgan'),
cookieParser = require('cookie-parser'),
bodyParser = require('body-parser'),
methodOverride = require('method-override'),
session = require('express-session'),
mongoStore = require('connect-mongo')(session),
config = require('./lib/config/config');
// 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.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
app.use(logger('dev'));
app.use(favicon(__dirname + '/app/favicon.ico'));
//app.use(bodyParser());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }) );
app.use(cookieParser());
//app.use(methodOverride());
app.use(express.static(path.join(__dirname + '/app')));
app.set('views', (path.join(__dirname + '/app/views')));
//app.use(express.static(path.join(__dirname, '/app')));
var expressSession = require('express-session');
app.use(expressSession({
secret: 'mySecretKey',
resave: true,
saveUninitialized: true,
store: new mongoStore({
url: config.db,
collection: 'sessions'
})
}));
// use passport session
app.use(passport.initialize());
app.use(passport.session());
//Bootstrap routes
var routes = require('./lib/config/routes')();
app.use('/', routes);
//var debug = require('debug')('roguelands:server');
var port = process.env.PORT || 8000;
app.set('port', port);
var server = http.createServer(app);
io = io.listen(server);
require('./lib/sockets/base')(io);
server.listen(port, function () {
console.log('Express server listening on port %d in %s mode', port, app.get('env'));
});