Make API_ENTRY_POINT configurable

This commit is contained in:
Raphaël Jakse 2020-11-14 11:02:50 +01:00
parent dddee16ee5
commit d74fa69464
2 changed files with 7 additions and 8 deletions

View 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",

View 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;
@ -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));