-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
47 lines (38 loc) · 1.33 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
const express = require('express');
const http = require('http');
const path = require('path');
const registerHelpers = require('./utils/registerHelpers');
const { Server } = require('socket.io');
const hbs = require('hbs');
const hbsutils = require('hbs-utils')(hbs);
const session = require('cookie-session');
const app = express();
const server = http.createServer(app);
const io = new Server(server);
const port = process.env.PORT || 80;
io.on('connect', socket => {
socket.on('room:join', roomName => socket.join(roomName));
});
const viewsPath = path.join(__dirname, './templates/views');
const partialsPath = path.join(__dirname, './templates/partials');
const publicPath = path.join(__dirname, './public');
app.set('view engine', 'hbs');
app.set('views', viewsPath);
hbsutils.registerWatchedPartials(partialsPath, { precompile: true });
app.use(express.static(publicPath));
app.use(session({
name: 'player_session',
secret: process.env.EXPRESS_SESSION_SECRET || 'unkown',
maxAge: 86400000,
sameSite: 'strict'
}));
registerHelpers();
module.exports.io = io;
const routes = require('./routes');
for (const route of routes) app.use(route.url, route.ref);
app.get('*', (req, res) => res.status(404).send());
module.exports.start = () => {
server.listen(port, () => {
console.log(`Listening to port ${port}...`);
});
};