-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (27 loc) · 1.17 KB
/
index.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
const express = require('express');
const passport = require('passport');
const session = require('express-session');
const sharedSesh = require('express-socket.io-session');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const EventEmitter = require('events');
const config = require('./config.json');
const app = express();
const server = require('http').createServer(app);
const io = require('socket.io')(server);
const sessionMiddleware = session({
secret: config.session.secret,
resave: true,
saveUninitialized: true,
});
io.use(sharedSesh(sessionMiddleware));
app.use(sessionMiddleware);
require('./lib/config/passportSetup')(passport);
app.set('view engine', 'ejs'); // allows the use of EJS as the frontend template language
app.use(express.static(`${__dirname}/public`)); // expresses all content in the public folder to the client
app.use(bodyParser());
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
require('./lib/routes')(app, passport); // sets app routing
require('./lib/sockets')(io); // handles server sockets
server.listen(config.port, 'localhost'); // starts the server on config port