-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
48 lines (38 loc) · 1.32 KB
/
app.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
const express = require('express');
const bodyParser = require('body-parser');
const cookieSession = require('cookie-session');
const cookieParser = require('cookie-parser');
const urllib = require('url');
const path = require('path');
const crypto = require('crypto');
const config = require('./config.json');
const defaultroutes = require('./routes/default');
const passwordauth = require('./routes/password');
const webuathnauth = require('./routes/webauthn.js');
const app = express();
app.use(bodyParser.json());
/* ----- session ----- */
app.use(cookieSession({
name: 'session',
keys: [crypto.randomBytes(32).toString('hex')],
// Cookie Options
maxAge: 24 * 60 * 60 * 1000 // 24 hours
}))
app.use(cookieParser())
/* ----- serve static ----- */
app.use(express.static(path.join(__dirname, 'static')));
app.use('/', defaultroutes)
app.use('/password', passwordauth)
app.use('/webauthn', webuathnauth)
/* ----- redirect to https ----- */
app.use(function(req, res, next) {
if ((req.get('X-Forwarded-Proto') !== 'https')) {
res.redirect('https://' + req.get('Host') + req.url);
} else
next();
});
const defaultPort = config.port || 5000;
const port = process.env.PORT || defaultPort;
app.listen(port);
console.log(`Started app on port ${port}`);
module.exports = app;