Last active
January 24, 2024 10:49
-
-
Save freddi301/7463693ae2705337d3439b960f07e5df to your computer and use it in GitHub Desktop.
MSW configuration for create-react-app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { setupWorker } from 'msw/browser' | |
// https://mswjs.io/docs/best-practices/typescript | |
// also ensure there is .env or env.local file | |
// with PUBLIC_URL=index set to something otherwise chrome wont load the mock service worker | |
const worker = setupWorker(/* here goes handlers */); | |
if (process.env.NODE_ENV === "development") { | |
if (window.location.pathname === process.env.PUBLIC_URL) { | |
window.location.pathname = process.env.PUBLIC_URL + "/"; | |
} | |
mockStarted = worker.start({ | |
serviceWorker: { | |
url: `${process.env.PUBLIC_URL}/mockServiceWorker.js`, | |
}, | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment