import { Event } from './entities/event'; declare var BASE_URL: string; export default function request(endpoint: string, callback: Function, data?: any) { let xmlhttp = new XMLHttpRequest(); let log = ""; if (data) { log = JSON.stringify(data); } xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == XMLHttpRequest.DONE) { if (xmlhttp.status == 200) { callback(this.response); } else if (xmlhttp.status != 200) { if (this.response == "") { console.log("[FATAL ERROR] The server is currently offline for maintentance. Logging is unavailable at this moment."); } else { console.log("[FATAL ERROR] " + this.response + ". Logging will not be continued for this session."); } } } }; xmlhttp.open("POST", BASE_URL + endpoint, true); xmlhttp.setRequestHeader("Content-type", "application/json"); if (log != "") { xmlhttp.send(log); } else { xmlhttp.send(); } }