This repository has been archived by the owner on Jun 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxy-route.js
53 lines (50 loc) · 1.58 KB
/
proxy-route.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
53
var upload = require('multer')({ dest: 'uploads/' })
var uuid = require('uuid-v4');
var fs = require('fs');
var config = require('./config');
module.exports = (app) => {
app.post(
'/submit',
upload.single('upload_file_minidump'),
(reqIn, resIn) => {
var guid = uuid();
console.log(guid, 'got a request');
var formData = {};
Object.keys(reqIn.body).forEach((key) => {
formData[key] = reqIn.body[key];
});
formData.Version = formData._version;
formData.ProductName = formData._productName;
formData.upload_file_minidump = fs.createReadStream(reqIn.file.path);
var headers = {};
Object.keys(reqIn.headers).forEach((key) => {
if (key.indexOf('content-') == -1) {
headers[key] = reqIn.headers[key];
}
});
headers.Host = headers.host = config.hostHeader;
var postData = {
url: config.url,
formData: formData,
headers: headers
};
console.log(guid, 'posting now');
request.post(postData)
.on('error', function(err) {
console.error(guid, err);
resIn.status(500).send(err);
})
.on('response', function(resUpstream) {
var body = '';
resUpstream.on('data', function(data) {
body += data;
});
resUpstream.on('end', function() {
body = body.replace('CrashID=', '');
resIn.status(resUpstream.statusCode).send(body);
console.log(guid, 'Upload successful!', resUpstream.statusCode, body);
});
});
}
);
};