Home Information - Your home, your data, organized.
Python
Replace hardcoded URL strings in JS with server-provided constants (#270)
Tony C56c583aa32aa
diff --git a/src/hi/environment/client.py b/src/hi/environment/client.pyindex 264eafbe..0e3347df 100644--- a/src/hi/environment/client.py+++ b/src/hi/environment/client.py@@ -11,12 +11,14 @@ class ClientConfig:needed."""- DEBUG : bool- ENVIRONMENT : str- VERSION : str- VIEW_MODE : str- VIEW_TYPE : str- IS_EDIT_MODE : bool+ DEBUG : bool+ ENVIRONMENT : str+ VERSION : str+ VIEW_MODE : str+ VIEW_TYPE : str+ IS_EDIT_MODE : bool+ API_STATUS_URL : str = ''+ CONSOLE_UNLOCK_URL : str = ''def to_json_dict(self) -> dict:"""diff --git a/src/hi/environment/context_processors.py b/src/hi/environment/context_processors.pyindex 51e2b42a..a95174b0 100644--- a/src/hi/environment/context_processors.py+++ b/src/hi/environment/context_processors.py@@ -1,4 +1,5 @@from django.conf import settings+from django.urls import reversefrom .client import ClientConfig@@ -23,6 +24,8 @@ def client_config(request):VIEW_MODE = str(request.view_parameters.view_mode),VIEW_TYPE = str(request.view_parameters.view_type) if request.view_parameters.view_type else None,IS_EDIT_MODE = request.view_parameters.is_editing,+ API_STATUS_URL = reverse( 'api_status' ),+ CONSOLE_UNLOCK_URL = reverse( 'console_unlock' ),)return {diff --git a/src/hi/static/js/main.js b/src/hi/static/js/main.jsindex 57cd01ee..1b4fbd69 100644--- a/src/hi/static/js/main.js+++ b/src/hi/static/js/main.js@@ -12,6 +12,10 @@DEBUG: window.HiClientConfig?.DEBUG ?? false,isEditMode: window.HiClientConfig?.IS_EDIT_MODE ?? false,+ // Server-provided URLs (via ClientConfig context processor)+ API_STATUS_URL: window.HiClientConfig?.API_STATUS_URL ?? '/api/status',+ CONSOLE_UNLOCK_URL: window.HiClientConfig?.CONSOLE_UNLOCK_URL ?? '/console/unlock',+MAIN_AREA_SELECTOR: '#hi-main-content',LOCATION_VIEW_AREA_SELECTOR: '#hi-location-view-main',LOCATION_VIEW_SVG_CLASS: 'hi-location-view-svg',diff --git a/src/hi/static/js/status.js b/src/hi/static/js/status.jsindex c4ea0a89..b8de0d6e 100644--- a/src/hi/static/js/status.js+++ b/src/hi/static/js/status.js@@ -26,7 +26,7 @@const ServerPollingIntervalMs = 3 * 1000;const PollingErrorNotifyTimeMs = 60 * 1000;const ServerErrorMessageSelector = '#hi-server-error-msg';- const ServerPollingUrl = '/api/status';+ const ServerPollingUrl = Hi.API_STATUS_URL;const ServerStartTimestampAttr = 'startTimestamp';const ServerTimestampAttr = 'timestamp';const LastServerTimestampAttr = 'lastTimestamp';@@ -34,7 +34,7 @@const IdReplaceUpdateMapAttr = 'idReplaceUpdateMap';const IdReplaceHashMapAttr = 'idReplaceHashMap';const ConsoleLockedAttr = 'consoleLocked';- const ConsoleUnlockUrl = '/console/unlock';+ const ConsoleUnlockUrl = Hi.CONSOLE_UNLOCK_URL;const TransientViewSuggestionAttr = 'transientViewSuggestion';const TransientViewUrlAttr = 'url';const TransientViewDurationSecondsAttr = 'durationSeconds';