const express = require('express'); const { hostname, port, authorization } = require('../config'); const helmet = require('helmet'); const compression = require('compression'); const cors = require('cors'); const app = express(); app.use(express.json()); app.use(express.urlencoded({ extended: true })); app.use(helmet()); app.use(compression()); app.use(cors()); module.exports = (client) => { app.get('/hello', async (req, res) => { return res.send(`Hello world`); }); app.post('/vote', async (req, res) => { const body = req.body; const auth = req.header('Authorization'); if (auth != authorization) return res.status(403), console.warn(`Vote rejected with authorization '${auth}'`); // if (body.bot != client.user.id) return res.status(403), console.warn(`Vote rejected with ID '${body.bot}'`); if (body.type == 'test') { console.log(`Test succeeded, is weekend:`, body.isWeekend); } else { console.log(`Vote`) client.vote(body.user); } }); app.listen(port, hostname, () => { setTimeout(() => { console.log(`Listening for votes on 164.68.110.213:${port}`); }, (1000 * 3)); }); }