-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (40 loc) · 983 Bytes
/
index.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
47
48
49
50
51
52
(function(){
'use strict';
var config = require('./config.json'),
BugBot = require('./lib/bugbot'),
bodyParser = require('body-parser'),
express = require('express'),
app = express();
var bugbot;
var report = function(req, res){
if(!req.body
|| !req.body.person
|| !req.body.comment
|| !req.body.server) {
return res.status(400)
.json({
status: 400,
message: "Bad Request"
});
}
bugbot.report(req.body);
return res
.header('Access-Control-Allow-Origin', '*')
.json({
status: 200,
message: "OK"
});
};
app.use( bodyParser.json() ); // to support JSON-encoded bodies
app.use( bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true
}) );
app.get('/', function (req, res) {
res.send('BugBot kicks you!');
});
app.post('/report', report);
app.listen(config.port, function () {
bugbot = new BugBot(config);
console.log(`BugBot listening on port ${config.port}!`);
});
})();