This repository has been archived by the owner on Mar 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
server.js
69 lines (59 loc) · 1.83 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
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 expressSession = require('express-session');
const SessionStore = require('connect-session-knex')(expressSession);
const con = require('./utils/connection');
const app = express();
const server = http.createServer(app);
const io = new Server(server);
const port = process.env.PORT || 80;
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.registerPartials(partialsPath, { precompile: true });
app.use(express.static(publicPath));
app.use(expressSession({
secret: process.env.EXPRESS_SESSION_SECRET || 'unkown',
cookie: {
sameSite: 'strict',
maxAge: 86400000,
},
resave: true,
saveUninitialized: false,
store: new SessionStore({
tablename: 'player_session',
knex: con,
}),
}));
registerHelpers();
module.exports.io = io;
//Routes
const login = require('./routes/login');
const register = require('./routes/register');
const sheet = require('./routes/sheet');
const dice = require('./routes/dice');
const avatar = require('./routes/avatar');
//End Routes
app.get('/', (req, res) => {
res.render('home');
});
app.use('/register', register);
app.use('/login', login);
app.use('/sheet', sheet);
app.use('/dice', dice);
app.use('/avatar', avatar);
app.get('*', (req, res) => {
res.status(404).end();
});
module.exports.start = () => {
server.listen(port, () => {
console.log(`Listening to port ${port}...`);
});
};