Make the URL used to reach the server configurable (APP_PATH)
authorphilippe lhardy <pl@artisanlogiciel.net>
Mon, 27 Apr 2020 17:44:49 +0000 (17:44 +0000)
committerRaphaël Jakse <raphael.gitlab@jakse.fr>
Mon, 27 Apr 2020 17:44:49 +0000 (17:44 +0000)
config.js.sample
trivabble.js

index 971c55b82bd7a4ddee6716568fd89e731f801376..beba4ee7bb2a2a13b8cb47c38c724281365f3562 100644 (file)
@@ -14,6 +14,9 @@ window.TrivabbleConf = {
     // Max consecutive tries before blacklisting WebSockets for the current session
     MAX_WEBSOCKET_ERRORS: 1,
 
+    // to tweak only if your webserver is shared with other conflicting resources at / ( ex: yunohost integration )
+    APP_PATH: "",
+
     // I don't like trailing commas, here is a nice message for you reading this file :-)
     HAVE_FUN: true
 };
index b26131aa96982231135773592c83ddb6b51c94d5..e832002ea5d15db2d56f3b5f44d32e4693d2496a 100644 (file)
@@ -27,7 +27,7 @@
 (function () {
     "use strict";
 
-    const VERSION = 202004222300;
+    const VERSION = 202004262313;
 
     const Conf = window.TrivabbleConf || {};
 
@@ -41,6 +41,7 @@
     setConf("ENABLE_WEBSOCKETS",    true);
     setConf("ENABLE_EVENT_SOURCE",  true);
     setConf("MAX_WEBSOCKET_ERRORS", 1);
+    setConf("APP_PATH",             "");
 
     const _ = (window.libD && libD.l10n) ? libD.l10n() : function (s) {return s;};
 
     let pollingServer = false;
     let connectionStopped = false;
 
+    // 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("/:trivabble/sse/" + JSON.stringify(cmdsWithContext()));
+            eventSource = new EventSource(getApiEntryPoint() + "/sse/" + JSON.stringify(cmdsWithContext()));
             bindConnectionEvents(eventSource);
             return;
         }
             webSocket = new WebSocket(
                 (window.location.protocol === "http:" ? "ws://" : "wss://") +
                 window.location.host +
-                "/:trivabble/ws/" +
+                getApiEntryPoint() + "/ws/" +
                 JSON.stringify(cmdsWithContext())
             );
 
     function xhrRequest(data, onreadystatechange) {
         const xhr = new XMLHttpRequest();
 
-        xhr.open("POST", "/:trivabble", true);
+        xhr.open("POST", getApiEntryPoint(), true);
         xhr.setRequestHeader("Content-Type", "text/plain");
         xhr.send(JSON.stringify(data));