From f746344cf82dda6d7561f250965efdc5cc45b94f Mon Sep 17 00:00:00 2001 From: Patryk Adamczyk Date: Wed, 23 Oct 2019 13:47:16 +0200 Subject: [PATCH] JavaScript Client --- client/client.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 client/client.js diff --git a/client/client.js b/client/client.js new file mode 100644 index 0000000..6b8f3fb --- /dev/null +++ b/client/client.js @@ -0,0 +1,18 @@ +function log(base_url, trace = false, variable = {}) { + return new Promise((resolve, reject) => { + let data = variable; + if (trace) { + const err = new Error(); + data = { + _var: 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; + }); +}