Skip to content

Commit 0f1b19b

Browse files
committed
FE+BE: BACKEND_API_URL for reverse proxies #1390
Signed-off-by: jokob-sk <jokob.sk@gmail.com>
1 parent 77803c1 commit 0f1b19b

28 files changed

Lines changed: 75 additions & 30 deletions

front/deviceDetails.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,9 @@ function initializeTabs () {
416416
showSpinner();
417417

418418
// Get data from the server
419-
const protocol = window.location.protocol.replace(':', '');
420-
const host = window.location.hostname;
421419
const apiToken = getSetting("API_TOKEN");
422-
const port = getSetting("GRAPHQL_PORT"); // same port your Flask app runs on
423420

424-
const apiBase = `${protocol}://${host}:${port}`;
421+
const apiBase = getApiBase();
425422
const url = `${apiBase}/device/${getMac()}?period=${encodeURIComponent(period)}`;
426423

427424
const response = await fetch(url, {

front/deviceDetailsEdit.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,10 @@ function getDeviceData() {
4343
mac = getMac()
4444

4545
console.log(mac);
46-
47-
const protocol = window.location.protocol.replace(':', '');
48-
const host = window.location.hostname;
4946
const apiToken = getSetting("API_TOKEN");
50-
const port = getSetting("GRAPHQL_PORT");
47+
let period = $("#period").val()
5148

52-
const apiBase = `${protocol}://${host}:${port}`;
49+
const apiBase = getApiBase();
5350
const url = `${apiBase}/device/${mac}?period=${encodeURIComponent(period)}`;
5451

5552
// get data from server

front/deviceDetailsEvents.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,9 @@ function loadEventsData() {
4848
)
4949
`;
5050

51-
const protocol = window.location.protocol.replace(':', '');
52-
const host = window.location.hostname;
53-
const port = getSetting("GRAPHQL_PORT");
5451
const apiToken = getSetting("API_TOKEN");
5552

56-
const apiBase = `${protocol}://${host}:${port}`;
53+
const apiBase = getApiBase();
5754
const url = `${apiBase}/dbquery/read`;
5855

5956
$.ajax({

front/deviceDetailsPresence.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,9 @@
3636
// ---------------------------------------
3737
// query data
3838
function loadPresenceData() {
39-
const protocol = window.location.protocol.replace(":", "");
40-
const host = window.location.hostname;
41-
const port = getSetting("GRAPHQL_PORT");
4239
const apiToken = getSetting("API_TOKEN");
4340

44-
const apiBase = `${protocol}://${host}:${port}`;
41+
const apiBase = getApiBase();
4542
const url = `${apiBase}/sessions/calendar`;
4643

4744
$('#calendar').fullCalendar('removeEventSources');

front/deviceDetailsSessions.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,9 @@ function loadSessionsData() {
103103
showSpinner();
104104

105105
// Build API base
106-
const protocol = window.location.protocol.replace(':', '');
107-
const host = window.location.hostname;
108-
const port = getSetting("GRAPHQL_PORT"); // or whatever port your Flask API runs on
109106
const apiToken = getSetting("API_TOKEN");
110107

111-
const apiBase = `${protocol}://${host}:${port}`;
108+
const apiBase = getApiBase();
112109
const url = `${apiBase}/sessions/${getMac()}?period=${encodeURIComponent(period)}`;
113110

114111
// Call API with Authorization header

front/js/api.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function getApiBase()
2+
{
3+
apiBase = getSetting("BACKEND_API_URL");
4+
5+
if(apiBase == "")
6+
{
7+
const protocol = window.location.protocol.replace(':', '');
8+
const host = window.location.hostname;
9+
const port = getSetting("GRAPHQL_PORT");
10+
11+
apiBase = `${protocol}://${host}:${port}`;
12+
}
13+
14+
return apiBase;
15+
}

front/php/templates/header.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<script src="lib/datatables.net/js/dataTables.select.min.js"></script>
4545

4646
<script src="js/common.js?v=<?php include 'php/templates/version.php'; ?>"></script>
47+
<script src="js/api.js?v=<?php include 'php/templates/version.php'; ?>"></script>
4748
<script src="js/modal.js?v=<?php include 'php/templates/version.php'; ?>"></script>
4849
<script src="js/tests.js?v=<?php include 'php/templates/version.php'; ?>"></script>
4950
<script src="js/db_methods.js?v=<?php include 'php/templates/version.php'; ?>"></script>

front/php/templates/language/ar_ar.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
"AppEvents_ObjectType": "Object Type",
2828
"AppEvents_Plugin": "المكونات الإضافية",
2929
"AppEvents_Type": "النوع",
30+
"BACKEND_API_URL_description": "",
31+
"BACKEND_API_URL_name": "",
3032
"BackDevDetail_Actions_Ask_Run": "هل تريد تنفيذ هذا الإجراء؟",
3133
"BackDevDetail_Actions_Not_Registered": "لم يتم تسجيل الإجراء: ",
3234
"BackDevDetail_Actions_Title_Run": "تنفيذ الإجراء",

front/php/templates/language/ca_ca.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
"AppEvents_ObjectType": "Tipus d'objecte",
2828
"AppEvents_Plugin": "Plugin",
2929
"AppEvents_Type": "Tipus",
30+
"BACKEND_API_URL_description": "",
31+
"BACKEND_API_URL_name": "",
3032
"BackDevDetail_Actions_Ask_Run": "Vol executar aquesta comanda?",
3133
"BackDevDetail_Actions_Not_Registered": "Comanda no registrada: ",
3234
"BackDevDetail_Actions_Title_Run": "Executar la comanda",
@@ -763,4 +765,4 @@
763765
"settings_system_label": "Sistema",
764766
"settings_update_item_warning": "Actualitza el valor sota. Sigues curós de seguir el format anterior. <b>No hi ha validació.</b>",
765767
"test_event_tooltip": "Deseu els canvis primer abans de comprovar la configuració."
766-
}
768+
}

front/php/templates/language/cs_cz.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
"AppEvents_ObjectType": "",
2828
"AppEvents_Plugin": "Zásuvný modul",
2929
"AppEvents_Type": "Typ",
30+
"BACKEND_API_URL_description": "",
31+
"BACKEND_API_URL_name": "",
3032
"BackDevDetail_Actions_Ask_Run": "",
3133
"BackDevDetail_Actions_Not_Registered": "",
3234
"BackDevDetail_Actions_Title_Run": "Spustit akci",

0 commit comments

Comments
 (0)