From d74fa69464c54d9aa76c49ab80149a635328d248 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Jakse?= Date: Sat, 14 Nov 2020 11:02:50 +0100 Subject: [PATCH] Make API_ENTRY_POINT configurable --- public/config.js.sample | 3 +++ public/trivabble.js | 12 ++++-------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/public/config.js.sample b/public/config.js.sample index 90b18f2..6580ac0 100644 --- a/public/config.js.sample +++ b/public/config.js.sample @@ -17,6 +17,9 @@ window.TrivabbleConf = { // To tweak only if your webserver is shared with other conflicting resources at / (e.g. Yunohost integration) APP_PATH: "", + // The API entry point. Default value: APP_PATH + '/:trivabble' + API_ENTRY_POINT: "/:trivabble", + // The color of the flash light when double clicking on a cell FLASH_LIGHT_COLOR: "#EE6633", diff --git a/public/trivabble.js b/public/trivabble.js index e61fd1d..a30090e 100644 --- a/public/trivabble.js +++ b/public/trivabble.js @@ -59,6 +59,7 @@ setConf("FLASH_LIGHT_DURATIONS", [800, 1600, 3200]); setConf("FLASH_LIGHT_DURATION", middle("FLASH_LIGHT_DURATIONS")); setConf("FLASH_LIGHT_COLOR", "#ee6633"); + setConf("API_ENTRY_POINT", Conf.APP_PATH + "/:trivabble"); function getSetting(key) { let type; @@ -194,11 +195,6 @@ let serverVersion = 0; - // HTTP path url prefix for any socket (xhr,ess or ws) from browser to server access - function getApiEntryPoint() { - return Conf.APP_PATH + "/:trivabble"; - } - function mouseDown(ele, fun, stop) { const meth = stop ? "removeEventListener" : "addEventListener"; ele[meth]("mousedown", fun, false); @@ -1307,7 +1303,7 @@ closeConnections(); pollingServer = true; - eventSource = new EventSource(getApiEntryPoint() + "/sse/" + JSON.stringify(cmdsWithContext())); + eventSource = new EventSource(Conf.API_ENTRY_POINT + "/sse/" + JSON.stringify(cmdsWithContext())); bindConnectionEvents(eventSource); return; } @@ -1323,7 +1319,7 @@ webSocket = new WebSocket( (window.location.protocol === "http:" ? "ws://" : "wss://") + window.location.host + - getApiEntryPoint() + "/ws/" + + Conf.API_ENTRY_POINT + "/ws/" + JSON.stringify(cmdsWithContext()) ); @@ -1337,7 +1333,7 @@ function xhrRequest(data, onreadystatechange) { const xhr = new XMLHttpRequest(); - xhr.open("POST", getApiEntryPoint(), true); + xhr.open("POST", Conf.API_ENTRY_POINT, true); xhr.setRequestHeader("Content-Type", "text/plain"); xhr.send(JSON.stringify(data)); -- 2.30.2