[reverse proxy] Use getApiBase() to get GraphQL Endpoint for front/deviceDetailsTools.php.#1396
Conversation
📝 WalkthroughWalkthroughThe pull request refactors Changes
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. Comment |
There was a problem hiding this comment.
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
📒 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/dbor relative paths. Use/datafor persistent config/db,/tmpfor 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
apiBasevariable 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
| // Build base URL dynamically | ||
| const apiBase = getApiBase(); | ||
| const apiToken = getSetting("API_TOKEN"); |
There was a problem hiding this comment.
🧩 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.phpRepository: 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.
| // Build base URL dynamically | ||
| const apiBase = getApiBase(); |
There was a problem hiding this comment.
🛠️ 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.
| // 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().
| const apiBase = getApiBase(); | ||
| const apiToken = getSetting("API_TOKEN"); // optional token if needed |
There was a problem hiding this comment.
🛠️ 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.
| 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.
| // Build base URL dynamically | ||
| const apiBase = getApiBase(); |
There was a problem hiding this comment.
🛠️ 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.
| // 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.
|
Oh, sorry, just did this part of this commit as I thought you didnt have time today: 0727798 |
Use
getApiBase()to get GraphQL Endpoint forfront/deviceDetailsTools.php.Note that you might want to check the Variable Names and see if
baseUrlorapiBaseis preferrable to you (it might not be fully consistent with the rest of the Code).Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.