-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathweb.js
More file actions
47 lines (39 loc) · 1.22 KB
/
web.js
File metadata and controls
47 lines (39 loc) · 1.22 KB
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
/**======= Copy right
Sait 2018
=====================*/
const express = require('express')
const bodyParser = require('body-parser')
const agenda = require('agenda')
const app = express()
const jobQueue = new agenda()
const config = require('./config.json')
const VoteScheduler = require('./schedulers/voteScheduler')
const path = '/dblwebhook'
const port = process.env.PORT || 5555
jobQueue.database(config.database, VoteScheduler.voteCollection, { useNewUrlParser: true });
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/', (req, res) => {
res.send('How did you find this owo');
})
app.use(path, async (req, res) => {
var auth = config.discordBotOrg.webhookAuth;
if (auth && auth !== req.headers.authorization) {
res.status(401).end();
return;
}
await jobQueue.start();
jobQueue.now(VoteScheduler.voteJob, {
header: {
host: req.headers.host,
origin: req.headers.origin,
// authorization: req.headers.authorization
},
body: req.body
}).then(() => {
res.status(200).end();
})
})
app.listen(port, () => {
console.log(`[Info] Webhook running at ${path} on port ${port}`);
})