-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
29 lines (27 loc) · 1.06 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
'use strict';
const express = require('express');
const session = require('express-session');
const bodyParser = require('body-parser');
const { resolve } = require('path');
const db = require('./db.json');
const app = express();
module.exports = app
.use(bodyParser.urlencoded({ extended: true }), bodyParser.json(), require('volleyball'), express.static(resolve(__dirname, 'public')))
.use(session({
// this mandatory configuration ensures that session IDs are not predictable
secret: 'tongiscool', // or whatever you like
// these options are recommended and reduce session concurrency issues
resave: false,
saveUnitialized: false
}))
.use(function (req, res, next) {
console.log('session', req.session);
next();
})
.use('/api', require('./api'))
// Send index.html for anything else.
.get('/*', (_, res) => res.sendFile(resolve(__dirname, 'public', 'index.html')))
.use(require('./error.middleware'));
const server = app.listen(process.env.PORT || 3000, () => {
console.log(`Listening on ${JSON.stringify(server.address())}`);
});