This repository has been archived by the owner on Mar 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
54 lines (49 loc) · 1.52 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
49
50
51
52
53
54
const express = require('express');
const session = require('express-session');
const redis = require('redis');
const bot = require('./bot');
const app = express();
const token = process.env.TOKEN;
/**
* Session handling, so there's a bunch of useful data available.
* This also initializes the connection to the Redis server which caches all the sessions.
*/
let redisClient = redis.createClient({
host: 'redis'
});
let storage = require('connect-redis')(session);
app.use(
session({
store: new storage({client: redisClient}),
secret: process.env.CLIENT_SECRET, // Why not?
resave: false,
saveUninitialized: false,
cookie: {
maxAge: 3 * 24 * 60 * 60 * 1000 // 3 days. Discord's tokens last 7 days. This is to prevent having to re-generate tokens, that's boring.
}
})
);
/**
* Setting routes.
*/
const routeIndex = require('./routes/index');
const routeDiscord = require('./routes/discord');
const routeLogin = require('./routes/login');
const routeLogout = require('./routes/logout');
const routeVerify = require('./routes/verify');
app.use('/discord', routeDiscord);
app.use('/login', routeLogin);
app.use('/logout', routeLogout);
app.use('/verify', routeVerify);
app.use('/assets', express.static('static/assets'));
app.use('/', routeIndex);
/**
* Starts the server when the bot is ready.
*/
bot.on('ready', () => {
console.log('Preparing webapp...');
app.listen(80, '0.0.0.0');
console.log('Ready.');
});
console.log('Logging in bot...');
bot.login(token);