-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
34 lines (30 loc) · 1.07 KB
/
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
const app = require('express')();
const fs = require('fs');
const path = require('path');
const BugCollector = require('.');
const collector = new BugCollector();
app.post('/', (req, res) => {
console.log('received bug report!');
let data = '';
req.on('data', chunk => data += chunk);
req.on('end', function() {
const report = JSON.parse(data);
return collector.hasReport(report).then(exists => {
if (exists) {
console.error('Report already exists. Skipping ingestion...');
res.sendStatus(200);
} else {
return collector.ingest(report)
.then(report => console.log('Report stored as', report._id))
.then(() => res.sendStatus(200));
}
})
});
});
app.get('/', (req, res) => {
res.send(`Bug-Catcher up and running! POST bug reports here to report bugs!`);
});
const port = +process.env.PORT || 8888;
collector.connect()
.then(() => app.listen(port))
.then(() => console.log('listening for bug reports on port:', port));