This repository has been archived by the owner on Feb 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
90 lines (72 loc) · 2.22 KB
/
index.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const express = require('express');
const expressVue = require('express-vue');
const http = require('http');
const path = require('path');
global.config = require('./config.json');
const { Client, Pool } = require('pg');
global.pg_pool = new Pool(config.db);
global.helpers = require('./helpers');
global.userMap = {};
const WebsocketServer = require('./backend/websocket');
const Strategy = require('passport-discord').Strategy;
const passport = require('passport');
const session = require('express-session');
const strategy = new Strategy({
clientID: global.config.appinfo.id,
clientSecret: global.config.appinfo.secret,
callbackURL: global.config.appinfo.callback,
scope: ['identify']
}, (accessToken, refreshToken, profile, done) => {
process.nextTick(() => {
return done(null, profile);
});
});
passport.use(strategy);
const app = express();
app.use(session({
secret: global.config.appinfo.othersecret,
resave: false,
saveUninitiated: true,
cookie: {
secure: false,
maxAge: 86400000,
httpOnly: false
}
}));
app.use(passport.initialize());
app.use(passport.session());
passport.serializeUser((user, done) => {
done(null, user);
});
passport.deserializeUser((obj, done) => {
done(null, obj);
});
app.set('views', path.join(__dirname, 'app', 'views'));
app.set('vue', {
componentsDir: path.join(__dirname, 'app', 'components'),
defaultLayout: 'layout'
});
app.engine('vue', expressVue);
app.set('view engine', 'vue');
app.use(express.static('public'));
app.use('/', require('./routes/main'));
app.use('/api', require('./routes/api'));
app.get('/login', passport.authenticate('discord', {
scope: ['identify']
}));
app.get('/callback', passport.authenticate('discord', {
failureRedirect: '/'
}), async (req, res) => {
console.log('A user has authenticated');
let rows = await global.pg_pool.query('SELECT token, salt FROM public.user WHERE id = $1', [req.user.id]);
if (rows.rows.length === 0) {
}
global.userMap[req.sessionID] = req.user.id;
res.redirect('/');
});
const websocketServer = new WebsocketServer(app);
const port = 8099;
app.listen(port, () => {
console.log('App listening on port', port);
});
require('./bot');