Skip to content

Commit 00a1875

Browse files
author
netalertx-fedora
committed
Use getApiBase() to get GraphQL Endpoint.
1 parent 82041f3 commit 00a1875

1 file changed

Lines changed: 17 additions & 23 deletions

File tree

front/deviceDetailsTools.php

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -210,23 +210,20 @@ class="btn btn-default pa-btn pa-btn-delete"
210210
<div id="scanoutput" style="margin-top: 30px;"></div>
211211

212212
<script>
213-
214-
const protocol = window.location.protocol;
215-
const host = window.location.hostname;
216-
const port = getSetting("GRAPHQL_PORT");
213+
// Build base URL dynamically
214+
const apiBase = getApiBase();
217215
const apiToken = getSetting("API_TOKEN");
218216

219217
// ----------------------------------------------------------------
220218
function manualnmapscan(targetip, mode) {
221219
$("#scanoutput").empty();
222220

223-
224-
const baseUrl = getApiBase();
225-
221+
// Build base URL dynamically
222+
const apiBase = getApiBase();
226223

227224
$.ajax({
228225
method: "POST",
229-
url: `${baseUrl}/nettools/nmap`,
226+
url: `${apiBase}/nettools/nmap`,
230227
contentType: "application/json",
231228
dataType: "json",
232229
data: JSON.stringify({
@@ -265,7 +262,7 @@ function speedtestcli() {
265262

266263
$.ajax({
267264
method: "GET",
268-
url: `${protocol}//${host}:${port}/nettools/speedtest`,
265+
url: `${apiBase}/nettools/speedtest`,
269266
headers: {
270267
"Authorization": "Bearer " + apiToken,
271268
"Content-Type": "application/json"
@@ -316,7 +313,7 @@ function traceroute() {
316313

317314
$.ajax({
318315
method: "POST",
319-
url: `${protocol}//${host}:${port}/nettools/traceroute`,
316+
url: `${apiBase}/nettools/traceroute`,
320317
headers: {
321318
"Authorization": "Bearer " + apiToken,
322319
"Content-Type": "application/json"
@@ -366,7 +363,7 @@ function nslookup() {
366363

367364
$.ajax({
368365
method: "POST",
369-
url: `${protocol}//${host}:${port}/nettools/nslookup`,
366+
url: `${apiBase}/nettools/nslookup`,
370367
headers: {
371368
"Authorization": "Bearer " + apiToken,
372369
"Content-Type": "application/json"
@@ -450,7 +447,7 @@ function wakeonlan() {
450447

451448
$.ajax({
452449
method: "POST",
453-
url: `${protocol}//${host}:${port}/nettools/wakeonlan`,
450+
url: `${apiBase}/nettools/wakeonlan`,
454451
headers: {
455452
"Authorization": "Bearer " + apiToken,
456453
"Content-Type": "application/json"
@@ -492,7 +489,7 @@ function copyFromDevice() {
492489

493490
$.ajax({
494491
method: "POST",
495-
url: `${protocol}//${host}:${port}/device/copy`,
492+
url: `${apiBase}/device/copy`,
496493
headers: {
497494
"Authorization": "Bearer " + apiToken,
498495
"Content-Type": "application/json"
@@ -585,18 +582,14 @@ function deleteDeviceEvents () {
585582
return;
586583
}
587584

588-
const protocol = window.location.protocol; // "http:" or "https:"
589-
const host = window.location.hostname; // current hostname
590-
const port = getSetting("GRAPHQL_PORT"); // your dynamic port
591-
const apiToken = getSetting("API_TOKEN"); // optional token if needed
592-
593585
// Build base URL dynamically
594-
const baseUrl = getApiBase();
586+
const apiBase = getApiBase();
587+
const apiToken = getSetting("API_TOKEN"); // optional token if needed
595588

596589
// Delete device events
597590
$.ajax({
598591
method: "DELETE",
599-
url: `${baseUrl}/device/${encodeURIComponent(mac)}/events/delete`,
592+
url: `${apiBase}/device/${encodeURIComponent(mac)}/events/delete`,
600593
headers: {
601594
"Authorization": "Bearer " + apiToken
602595
},
@@ -641,11 +634,12 @@ function resetDeviceProps () {
641634
return;
642635
}
643636

644-
const baseUrl = getApiBase();
637+
// Build base URL dynamically
638+
const apiBase = getApiBase();
645639

646640
$.ajax({
647641
method: "POST",
648-
url: `${baseUrl}/device/${encodeURIComponent(mac)}/reset-props`,
642+
url: `${apiBase}/device/${encodeURIComponent(mac)}/reset-props`,
649643
dataType: "json",
650644
headers: {
651645
"Authorization": "Bearer " + apiToken
@@ -675,7 +669,7 @@ function internetinfo() {
675669

676670
$.ajax({
677671
method: "GET",
678-
url: `${protocol}//${host}:${port}/nettools/internetinfo`,
672+
url: `${apiBase}/nettools/internetinfo`,
679673
headers: {
680674
"Authorization": "Bearer " + apiToken,
681675
"Content-Type": "application/json"

0 commit comments

Comments
 (0)