-
Notifications
You must be signed in to change notification settings - Fork 5
/
server.js
52 lines (41 loc) · 1.43 KB
/
server.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
const express = require('express');
const multer = require('multer');
const bodyParser = require('body-parser');
const uuid = require('uuid');
const writeFile = require('write-file');
const path = require('path');
const http = require('http');
const app = express();
const server = http.createServer(app);
app.use(bodyParser.urlencoded({ extended: false }));
const crashesPath = path.join(__dirname, 'crashes');
const exceptionsPath = path.join(__dirname, 'uncaughtexceptions');
const upload = multer({
dest: crashesPath,
}).single('upload_file_minidump');
app.post('/crashreports', upload, (request, response) => {
const body = {
...request.body,
filename: request.file.filename,
date: new Date(),
};
const filePath = `${request.file.path}.json`;
const report = JSON.stringify(body);
writeFile(filePath, report, error => {
if (error) return console.error('Error Saving', report);
console.log('Crash Saved', filePath, report);
});
response.end();
});
app.post('/uncaughtexceptions', (request, response) => {
const filePath = path.join(exceptionsPath, `${uuid()}.json`);
const report = JSON.stringify({ ...request.body, date: new Date() });
writeFile(filePath, report, error => {
if (error) return console.error('Error Saving', report);
console.log('Exception Saved', filePath, report);
});
response.end();
});
server.listen(3000, () => {
console.log('Crash report server running on Port 3000.');
});