-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebhook.js
More file actions
31 lines (27 loc) · 779 Bytes
/
webhook.js
File metadata and controls
31 lines (27 loc) · 779 Bytes
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
/* eslint-disable require-jsdoc */
const EventEmitter = require('events');
const express = require('express');
const app = express();
class TCAPIWebhook extends EventEmitter {
/**
*
* @param {number} port The port the server should work on
* @param {string} path the path the server will be listening on
*/
constructor(port, path) {
super();
this.port = port;
this.path = path;
this.listening();
}
listening() {
app.use(express.json());
app.post(this.path || '/tcapijs', (req, res) => {
this.emit('vote', {userID: req.body.User.ClientID, date: req.body.User.Date});
});
app.listen(this.port, () => {
this.emit('listening', {port: this.port, path: this.path || '/tcapijs'});
});
}
}
module.exports = TCAPIWebhook;