cd-ddos-hook
Version:
Send/Receiver For DDoS Detection
26 lines (21 loc) • 725 B
JavaScript
const EventEmitter = require('events');
const express = require('express');
const bodyParser = require('body-parser');
const Receiver = require('./Receiver');
class Sender extends EventEmitter {
constructor(path = '/api', port = 3000) {
super();
this.app = express();
this.options = { path, port };
this.app.use(bodyParser.json());
this.app.use(bodyParser.urlencoded({ extended: true }));
this.app.post(this.options.path, (req, res) => {
const send = new Receiver(req.body);
this.emit("api", send);
});
}
start(cb) {
return this.app.listen(this.options.port, cb);
}
}
module.exports = Sender