-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
75 lines (65 loc) · 2.16 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
var express = require('express'),
connect = require('connect'),
bodyParser = require('body-parser'),
cookieParser = require('cookie-parser'),
mongoose = require('mongoose'),
flash = require('connect-flash'),
session = require('express-session'),
passport = require('passport'),
passportSocketIo = require("passport.socketio"),
dbConfig = require('./config/db');
var EXPRESS_SID_KEY = 'express.sid';
var COOKIE_SECRET = 'keyboard cat';
// Create a new store in mongo for the Express sessions
var MongoStore = require('connect-mongo-store')(connect);
var mongoStore = new MongoStore(dbConfig.url);
/**************************
* Database
* Load and initialize sockets
**************************/
mongoose.connect(dbConfig.url);
/**************************
* App initialization
* Load and initialize sockets
**************************/
var app = express(),
server = app.listen(3000),
io = require('socket.io').listen(server);
/**************************
* Middleware handlers
* Load and initialize sockets
**************************/
app.use(cookieParser(COOKIE_SECRET));
app.use(bodyParser());
app.use(session( { store: mongoStore, secret: COOKIE_SECRET, key: EXPRESS_SID_KEY } ));
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
app.set('view engine', 'jade');
app.set('views', __dirname + '/app/views');
app.use(express.static(__dirname + '/public'));
/**************************
* Passport configuration
* Set up users and authentication strategies
**************************/
require('./config/passport')(passport);
/**************************
* Sockets
* Load and initialize sockets
**************************/
require('./app/sockets.js')(io);
/**************************
* Routes
* Load and initialize routes
**************************/
require('./app/routes.js')(app, passport);
require('./app/adminroutes.js')(app);
/***************************
* Socket authentication
***************************/
io.set('authorization', passportSocketIo.authorize({
cookieParser: cookieParser,
key: EXPRESS_SID_KEY,
secret: COOKIE_SECRET,
store: mongoStore
}));