Repository navigation
fix(socketclient): respect basePath when importing Socket.IO client - #4353
Conversation
|
Thanks for the fix! It looks good! 🙂 The separate const basePath = globalThis.config?.basePath ?? "/";
const socketIo = await import(
/* @vite-ignore */ `${basePath}socket.io/socket.io.esm.min.js`
);The CodeQL findings look like false positives to me, since all calls execute successfully in the tests. I’d prefer covering this with an end-to-end test, since the important behavior is that the Socket.IO client actually loads when MagicMirror is served under a configured |
Follow up on review: keep the one-line URL calculation in socketclient.js instead of a dedicated helper, and cover the real behavior end to end. The browser client imported the Socket.IO ES module from a hardcoded absolute /socket.io/... URL. When MagicMirror is served under a configured basePath (e.g. /dashboard/ behind a reverse proxy), the browser requested the module from the site root instead and the page never started. Resolve the module URL from globalThis.config.basePath, generated from the active config by config/basepath.js, with a "/" fallback. Add a Playwright e2e test that emulates a reverse proxy mounting MagicMirror at /dashboard/ and checks that the client module actually loads; the default "/" basePath is covered as well. Fixes MagicMirrorOrg#4352 AI-assisted: change and tests were drafted with an AI coding agent and verified locally (fail-before/pass-after e2e, ESLint, Prettier). Signed-off-by: TINGyu123644 <TINGyu123644@users.noreply.github.com>
6a0df55 to
33af682
Compare
|
@KristjanESPERANTO Thanks for the review and the concrete suggestion — agreed the helper was overkill. I pushed
Agreed the CodeQL findings look like false positives — the URL uses the same config-generated |
Fixes #4352
What this changes
js/socketclient.jsimported the Socket.IO ES module from the hardcoded absolute URL/socket.io/socket.io.esm.min.js, ignoring a configuredbasePath. Under a sub-path deployment (e.g./dashboard/behind a reverse proxy) the dynamic import failed and the page never started.globalThis.config.basePath(generated from the active config byconfig/basepath.js), with/as the fallback — the same value already used for the socket connection path./dashboard/and checks the browser actually loads the client module from the prefixed URL. The default/base path is covered as well.Verification
npx vitest run tests/e2e/socketclient_basepath_spec.js— 2/2 pass; the/dashboard/case times out against the old hardcoded URL (fail-before / pass-after).npx eslintwith--max-warnings=0andnpx prettier --checkon all changed files — clean.weathergov_spec.js,yr_spec.js), unrelated to this change.AI disclosure
This change and its tests were drafted with an AI coding agent. I reviewed the logic, reproduced the failure end to end, ran the targeted tests, ESLint and Prettier locally, and take full responsibility for the contribution.