Description
Problem
The mock API setup in the repository hardcodes the base URL to http://localhost:3000 inside src/mocks/browser.js.
const url = http://localhost:3000/${endpoint};
However, when running the dev server, the application may start on a different port (e.g. 3001, 3002, etc.) if port 3000 is already in use.
Because of this, Mock Service Worker (MSW) fails to intercept the requests, since the requests originate from another port.
Example
If the app runs on:
http://localhost:3002
but the mock endpoint is:
http://localhost:3000/api/...
MSW does not match the request, resulting in unmocked network calls or failures during local development.
Expected behavior:
Use window.location.origin instead of a hardcoded port so that the mock endpoints automatically match the current origin.
Ensures the mock API works regardless of which port the development server runs on. Also makes the mock environment port-agnostic and Prevents mock intercept failures during local development
Additional Information
This issue was discovered while running the dev server on port 3002, where all MSW intercepts failed due to the hardcoded localhost:3000.
Description
Problem
The mock API setup in the repository hardcodes the base URL to http://localhost:3000 inside src/mocks/browser.js.
const url =
http://localhost:3000/${endpoint};However, when running the dev server, the application may start on a different port (e.g. 3001, 3002, etc.) if port 3000 is already in use.
Because of this, Mock Service Worker (MSW) fails to intercept the requests, since the requests originate from another port.
Example
If the app runs on:
http://localhost:3002
but the mock endpoint is:
http://localhost:3000/api/...
MSW does not match the request, resulting in unmocked network calls or failures during local development.
Expected behavior:
Use window.location.origin instead of a hardcoded port so that the mock endpoints automatically match the current origin.
Ensures the mock API works regardless of which port the development server runs on. Also makes the mock environment port-agnostic and Prevents mock intercept failures during local development
Additional Information
This issue was discovered while running the dev server on port 3002, where all MSW intercepts failed due to the hardcoded localhost:3000.