-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathhttp.js
46 lines (39 loc) · 1.04 KB
/
http.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
const express = require("express");
const bodyParser = require("body-parser");
const { logger } = require("./logger");
const { handleButtonUpdate, slackConf } = require("./slack/reminder");
const { getVolunteersNearAddress } = require("./slack/getVolunteersNearAddress");
const app = express();
const port = 3000;
app.use(
bodyParser.urlencoded({
extended: false,
})
);
app.get("/", (req, res) => res.send("ok"));
// this route is handling slack update buttons
app.post("/slack/actions/", (req, res) => {
if (slackConf(req)) {
const body = JSON.parse(req.body.payload);
res.sendStatus(200);
handleButtonUpdate(body);
} else {
res.status(400).send("Ignore this request.");
}
});
app.post("/slack/address/", (req, res) => {
if (slackConf(req)) {
res.sendStatus(200);
getVolunteersNearAddress(req.body);
} else {
res.status(400).send("Ignore this request.");
}
});
function run() {
app.listen(port, () =>
logger.info(`Health check running: http://localhost:${port}`)
);
}
module.exports = {
run,
};