Skip to content

[reverse proxy] Use getApiBase() to get GraphQL Endpoint for front/deviceDetailsTools.php.#1396

Merged
jokob-sk merged 1 commit intonetalertx:mainfrom
luckylinux:fix-devices-tools
Jan 9, 2026
Merged

[reverse proxy] Use getApiBase() to get GraphQL Endpoint for front/deviceDetailsTools.php.#1396
jokob-sk merged 1 commit intonetalertx:mainfrom
luckylinux:fix-devices-tools

Conversation

@luckylinux
Copy link
Contributor

@luckylinux luckylinux commented Jan 9, 2026

Use getApiBase() to get GraphQL Endpoint for front/deviceDetailsTools.php.

Note that you might want to check the Variable Names and see if baseUrl or apiBase is preferrable to you (it might not be fully consistent with the rest of the Code).

Summary by CodeRabbit

  • Refactor
    • Improved API base URL handling by centralizing configuration management, replacing hard-coded URL construction with dynamic retrieval across API calls.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 9, 2026

📝 Walkthrough

Walkthrough

The pull request refactors front/deviceDetailsTools.php to centralize base URL construction by replacing hard-coded protocol/host/port assembly with a dynamic apiBase variable retrieved via getApiBase(). This reduces code duplication across multiple AJAX calls to nettools and device endpoints while preserving existing request structure, headers, and error handling.

Changes

Cohort / File(s) Summary
URL Construction Refactoring
front/deviceDetailsTools.php
Replaced hard-coded base URL construction (protocol/host/port) with dynamic apiBase from getApiBase(). Updated AJAX calls to use ${apiBase}/... pattern across nettools and device endpoints. Removed redundant baseUrl declarations and added clarifying comments. API token retrieval and error handling remain unchanged.

Poem

🐰 URLs once scattered, now they're neat,
One base to rule them all—what a treat!
The rabbit hops through cleaner code,
No more hard-coding down this road!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: replacing hard-coded base URL construction with getApiBase() function in front/deviceDetailsTools.php for reverse proxy support.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Fix all issues with AI agents
In @front/deviceDetailsTools.php:
- Around line 221-222: The code redundantly redeclares and reinitializes apiBase
by calling getApiBase() again; remove the local declaration "const apiBase =
getApiBase()" and instead use the existing global apiBase variable already
initialized earlier, ensuring references in the surrounding functions (e.g., any
calls that rely on apiBase in this block) continue to use the global without
re-calling getApiBase().
- Around line 213-215: Remove redundant local redeclarations of apiBase and
apiToken and rely on the global variables initialized via getApiBase() and
getSetting("API_TOKEN"); specifically, keep the top-level declarations const
apiBase = getApiBase() and const apiToken = getSetting("API_TOKEN") and delete
any subsequent local declarations that shadow them (e.g., the extra const/let
apiBase and apiToken occurrences inside functions or blocks such as those near
usages for API endpoint construction and token access), ensuring all functions
use the global apiBase and apiToken variables and no other local redeclarations
remain.
- Around line 586-587: Remove the redundant local declarations of apiBase and
apiToken in this scope — they are already declared globally (apiBase, apiToken)
so delete the two const lines here; update the comment for apiToken to reflect
that the token is required for the Authorization header usage (where the header
is set) instead of saying "optional token if needed" to avoid misleading
readers.
- Around line 637-638: Remove the redundant local declaration "const apiBase =
getApiBase();" so the code uses the already-defined global apiBase (declared
earlier) for consistency with apiToken; replace any local references relying on
that line with the global variable and ensure getApiBase is not re-invoked in
this scope.
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 44eba4c and 00a1875.

📒 Files selected for processing (1)
  • front/deviceDetailsTools.php
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{py,php,js}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use environment variables (NETALERTX_DB, NETALERTX_LOG, etc.) everywhere instead of hardcoding /data/db or relative paths. Use /data for persistent config/db, /tmp for runtime logs/api/nginx state

Files:

  • front/deviceDetailsTools.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: docker_dev
  • GitHub Check: docker-tests
🔇 Additional comments (1)
front/deviceDetailsTools.php (1)

226-226: Excellent refactoring to centralize API endpoint construction.

All AJAX calls have been consistently updated to use the apiBase variable with proper template literal syntax. This eliminates code duplication and makes it easier to configure the base URL dynamically (e.g., for reverse proxy scenarios).

Also applies to: 265-265, 316-316, 366-366, 450-450, 492-492, 592-592, 642-642, 672-672

Comment on lines +213 to 215
// Build base URL dynamically
const apiBase = getApiBase();
const apiToken = getSetting("API_TOKEN");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify getApiBase() function definition and naming consistency

echo "=== Searching for getApiBase() function definition ==="
rg -n 'function\s+getApiBase|const\s+getApiBase|getApiBase\s*=' --type=js --type=php -A 5

echo -e "\n=== Searching for baseUrl variable/function ==="
rg -n '\bbaseUrl\b' --type=js --type=php -C 2

echo -e "\n=== Context around lines 213-215 in deviceDetailsTools.php ==="
sed -n '210,220p' front/deviceDetailsTools.php

echo -e "\n=== Redundant apiBase declarations mentioned in scratchpad ==="
sed -n '220,225p' front/deviceDetailsTools.php
sed -n '585,590p' front/deviceDetailsTools.php
sed -n '635,645p' front/deviceDetailsTools.php

Repository: jokob-sk/NetAlertX

Length of output: 1948


Confirm getApiBase() function exists; remove redundant local variable declarations.

The getApiBase() function is properly defined in front/js/api.js and correctly retrieves the backend API URL from settings. The naming is consistent with the codebase—baseUrl in deviceDetails.php is for page navigation, while apiBase in deviceDetailsTools.php is for API endpoint construction, serving different purposes.

However, the global declarations at lines 213-215 are sufficient for all functions in this script block. The redundant local redeclarations of apiBase and apiToken at lines 221-222, 586-587, and 637-638 are unnecessary and create confusion. Remove these local redeclarations and rely on the global variables declared at the top of the script.

🤖 Prompt for AI Agents
In @front/deviceDetailsTools.php around lines 213 - 215, Remove redundant local
redeclarations of apiBase and apiToken and rely on the global variables
initialized via getApiBase() and getSetting("API_TOKEN"); specifically, keep the
top-level declarations const apiBase = getApiBase() and const apiToken =
getSetting("API_TOKEN") and delete any subsequent local declarations that shadow
them (e.g., the extra const/let apiBase and apiToken occurrences inside
functions or blocks such as those near usages for API endpoint construction and
token access), ensuring all functions use the global apiBase and apiToken
variables and no other local redeclarations remain.

Comment on lines +221 to +222
// Build base URL dynamically
const apiBase = getApiBase();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Remove redundant apiBase declaration.

The apiBase variable is already declared globally at line 214 and is accessible throughout this script. Re-declaring it here is redundant, creates unnecessary overhead by calling getApiBase() again, and may confuse future maintainers.

♻️ Proposed fix
-        // Build base URL dynamically
-        const apiBase = getApiBase();
-
         $.ajax({
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Build base URL dynamically
const apiBase = getApiBase();
$.ajax({
🤖 Prompt for AI Agents
In @front/deviceDetailsTools.php around lines 221 - 222, The code redundantly
redeclares and reinitializes apiBase by calling getApiBase() again; remove the
local declaration "const apiBase = getApiBase()" and instead use the existing
global apiBase variable already initialized earlier, ensuring references in the
surrounding functions (e.g., any calls that rely on apiBase in this block)
continue to use the global without re-calling getApiBase().

Comment on lines +586 to +587
const apiBase = getApiBase();
const apiToken = getSetting("API_TOKEN"); // optional token if needed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Remove redundant declarations and fix misleading comment.

Both apiBase and apiToken are already declared globally (lines 214-215) and are accessible here. Additionally, the comment "optional token if needed" is misleading since the token is required for the authorization header at line 594.

♻️ Proposed fix
-        // Build base URL dynamically
-        const apiBase = getApiBase();
-        const apiToken = getSetting("API_TOKEN");   // optional token if needed
-
         // Delete device events
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const apiBase = getApiBase();
const apiToken = getSetting("API_TOKEN"); // optional token if needed
// Delete device events
🤖 Prompt for AI Agents
In @front/deviceDetailsTools.php around lines 586 - 587, Remove the redundant
local declarations of apiBase and apiToken in this scope — they are already
declared globally (apiBase, apiToken) so delete the two const lines here; update
the comment for apiToken to reflect that the token is required for the
Authorization header usage (where the header is set) instead of saying "optional
token if needed" to avoid misleading readers.

Comment on lines +637 to +638
// Build base URL dynamically
const apiBase = getApiBase();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Remove redundant apiBase declaration for consistency.

The apiBase variable is redeclared here, but apiToken (used at line 645) relies on the global declaration. This creates an inconsistency. Use the global apiBase from line 214 for consistency.

♻️ Proposed fix
-        // Build base URL dynamically
-        const apiBase = getApiBase();
-
         $.ajax({
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Build base URL dynamically
const apiBase = getApiBase();
🤖 Prompt for AI Agents
In @front/deviceDetailsTools.php around lines 637 - 638, Remove the redundant
local declaration "const apiBase = getApiBase();" so the code uses the
already-defined global apiBase (declared earlier) for consistency with apiToken;
replace any local references relying on that line with the global variable and
ensure getApiBase is not re-invoked in this scope.

@jokob-sk
Copy link
Collaborator

jokob-sk commented Jan 9, 2026

Oh, sorry, just did this part of this commit as I thought you didnt have time today: 0727798

@jokob-sk jokob-sk merged commit 00a1875 into netalertx:main Jan 9, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants