Skip to content

fix(mocks): use dynamic origin for MSW url (#177)#191

Open
rupeshca007 wants to merge 1 commit intoNetflix:masterfrom
rupeshca007:fix-issue-177
Open

fix(mocks): use dynamic origin for MSW url (#177)#191
rupeshca007 wants to merge 1 commit intoNetflix:masterfrom
rupeshca007:fix-issue-177

Conversation

@rupeshca007
Copy link
Copy Markdown

@rupeshca007 rupeshca007 commented Mar 25, 2026

Description

Fixes #177.

This PR resolves an issue where the Mock Service Worker (MSW) endpoints were hardcoded to http://localhost:3000. This caused mock intercept failures whenever the development server started on a different port (e.g. 3001, 3002), which often happens if port 3000 is already in use.

Changes

  • Dynamic Origin Detection: Replaced the hardcoded base URL with window.location.origin in stantardGetEndpoint.
    • Protocol-Agnostic WebSockets: Updated the WebSocket API setup to dynamically determine both the protocol (ws: or wss:) and the host from the current browser environment, ensuring compatibility across different deployment scenarios.

Verification Results

This fix has been thoroughly tested locally:

  • Alternative Port Simulation: Forced the development server to run on Port 3002 using $env:PORT="3002"; npm run start-with-mocks.
    • Automated Browser Audit: Verified using a real browser to ensure MSW intercepted traffic correctly on port 3002.
    • Confirmed Interception: Inspected logs to verify that MSW successfully intercepted traffic on port 3002.
    • WebSocket Validation: Verified that the mock WebSocket connection correctly initialized and handled __ping__ / __pong__ messages using the dynamic host configuration.

@rupeshca007 rupeshca007 changed the title Fix hardcoded MSW mock endpoints (Fixes #177) fix(mocks): use dynamic origin for MSW url (#177) Mar 25, 2026
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.

MSW mock endpoints hardcoded to localhost:3000 causing mock failures on different dev ports

1 participant