From b9f8bba621e91bfb75a7bc09ee53733ef2ecfd84 Mon Sep 17 00:00:00 2001 From: moksha-hub Date: Thu, 26 Feb 2026 21:19:11 +0530 Subject: [PATCH 1/2] fix: replace hardcoded IP with dynamic backend URL in reflection.js The PORT value was hardcoded to a specific AWS IP address (http://3.105.177.138:8000), which causes two problems: 1. Mixed-content security errors on musicblocks.sugarlabs.org (HTTPS page loading HTTP resource) causing the widget to silently fail. 2. Local development requires manually editing the source file every time. This commit replaces the hardcoded value with the same environment- aware dynamic resolver already used in aidebugger.js: - localhost / 127.0.0.1 -> http://localhost:8000 - musicblocks.sugarlabs.org -> https://api.musicblocks.sugarlabs.org - Any other host -> protocol//hostname:8000 Fixes: https://github.com/sugarlabs/musicblocks/issues/TBD --- js/widgets/reflection.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/js/widgets/reflection.js b/js/widgets/reflection.js index 5941359161..71f0705db8 100644 --- a/js/widgets/reflection.js +++ b/js/widgets/reflection.js @@ -76,7 +76,20 @@ class ReflectionMatrix { this.isOpen = true; this.isMaximized = false; this.activity.isInputON = true; - this.PORT = "http://3.105.177.138:8000"; // http://127.0.0.1:8000 + this.PORT = (() => { + if ( + window.location.hostname === "localhost" || + window.location.hostname === "127.0.0.1" + ) { + return "http://localhost:8000"; + } else if ( + window.location.hostname.includes("musicblocks.sugarlabs.org") + ) { + return `${window.location.protocol}//api.musicblocks.sugarlabs.org`; + } else { + return `${window.location.protocol}//${window.location.hostname}:8000`; + } + })(); const widgetWindow = window.widgetWindows.windowFor(this, "reflection", "reflection"); this.widgetWindow = widgetWindow; From 4c2728da69b5dbf25a1a8249a4b5ba93a9176996 Mon Sep 17 00:00:00 2001 From: moksha-hub Date: Thu, 26 Feb 2026 21:37:39 +0530 Subject: [PATCH 2/2] style: run Prettier on reflection.js and fix PORT test assertion - Reformat reflection.js with Prettier to pass lint CI - Update reflection.test.js PORT expectation: dynamic URL resolver returns 'http://localhost:8000' in jsdom (Jest test environment) instead of the old hardcoded AWS IP --- js/widgets/__tests__/reflection.test.js | 2 +- js/widgets/reflection.js | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/js/widgets/__tests__/reflection.test.js b/js/widgets/__tests__/reflection.test.js index 2e375b781f..d9fdefe711 100644 --- a/js/widgets/__tests__/reflection.test.js +++ b/js/widgets/__tests__/reflection.test.js @@ -124,7 +124,7 @@ describe("ReflectionMatrix", () => { expect(reflection.isOpen).toBe(true); expect(reflection.isMaximized).toBe(false); expect(mockActivity.isInputON).toBe(true); - expect(reflection.PORT).toBe("http://3.105.177.138:8000"); + expect(reflection.PORT).toBe("http://localhost:8000"); expect(window.widgetWindows.windowFor).toHaveBeenCalledWith( reflection, diff --git a/js/widgets/reflection.js b/js/widgets/reflection.js index 71f0705db8..6ca9b70ca5 100644 --- a/js/widgets/reflection.js +++ b/js/widgets/reflection.js @@ -82,9 +82,7 @@ class ReflectionMatrix { window.location.hostname === "127.0.0.1" ) { return "http://localhost:8000"; - } else if ( - window.location.hostname.includes("musicblocks.sugarlabs.org") - ) { + } else if (window.location.hostname.includes("musicblocks.sugarlabs.org")) { return `${window.location.protocol}//api.musicblocks.sugarlabs.org`; } else { return `${window.location.protocol}//${window.location.hostname}:8000`;