Skip to content

Commit

Permalink
Added To JavaScript Client Support for Node.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Patryk Adamczyk committed Oct 23, 2019
1 parent f746344 commit 8618412
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,29 @@ function log(base_url, trace = false, variable = {}) {
_trace: err.stack,
};
}
let xhr = new XMLHttpRequest();
xhr.open('POST', `${base_url}/logger`);
xhr.setRequestHeader('Content-type', 'application/json; charset=utf-8');
xhr.send(JSON.stringify(data));
xhr.onload = resolve;
xhr.onerror = reject;
data = JSON.stringify(data);
const url = `${base_url}/logger`;
let xhr;
try {
xhr = new XMLHttpRequest();
xhr.open('POST', url);
xhr.setRequestHeader('Content-type', 'application/json; charset=utf-8');
xhr.send(data);
xhr.onload = resolve;
xhr.onerror = reject;
} catch (e) {
const http = require('http');
const req = http.request(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
}, (res) => {
res.on('end', resolve);
});
req.on('error', reject);
req.write(data);
req.end();
}
});
}

0 comments on commit 8618412

Please sign in to comment.