-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
40 lines (32 loc) · 943 Bytes
/
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
const dotenv = require('dotenv');
dotenv.config();
const express = require('express');
const bodyParser = require('body-parser');
const verifyWebhookSignature = require('./util/verifyWebhookSignature');
const {
handleCreate,
handleUpdate,
handleCancel,
} = require('./controllers/webhooks');
const app = express();
const port = process.env.PORT || 3000;
app.use(bodyParser.json());
app.post('/webhook-catcher', verifyWebhookSignature, async (req, res) => {
const request = req.body;
switch (request.notification_type) {
case 'create':
return await handleCreate(request, res);
case 'change':
return await handleUpdate(request, res);
case 'cancel':
return await handleCancel(request, res);
default:
console.info(
'Some other webhook was received:',
request.notification_type
);
}
});
app.listen(port, () => {
console.info(`Server running on port ${port}`);
});