Make API_ENTRY_POINT configurable
authorRaphaël Jakse <raphael.trivabble@jakse.fr>
Sat, 14 Nov 2020 10:02:50 +0000 (11:02 +0100)
committerRaphaël Jakse <raphael.trivabble@jakse.fr>
Sat, 14 Nov 2020 10:02:50 +0000 (11:02 +0100)
public/config.js.sample
public/trivabble.js

index 90b18f2d8c78f4309cdd18decd5763fa9ff3472b..6580ac0bc5c28ffbbd2defa955633d821ce0bb0d 100644 (file)
@@ -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",
 
index e61fd1d88ae4073eee342d979f81bac55ed67f72..a30090e9cb6e24e996296d74da4a755f87ccbedd 100644 (file)
@@ -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;
 
     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);
             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;
         }
             webSocket = new WebSocket(
                 (window.location.protocol === "http:" ? "ws://" : "wss://") +
                 window.location.host +
-                getApiEntryPoint() + "/ws/" +
+                Conf.API_ENTRY_POINT + "/ws/" +
                 JSON.stringify(cmdsWithContext())
             );
 
     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));