Bypass Webpack dev server url? #871
-
I'm using msw
Same for react dev tools:
Is it possible to bypass only this url? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey, @adesurirey. We've enabled the "warn" strategy for all unhandled requests a few minor versions back. The reason for that is to improve developer experience (I know this sounds counter-intuitive right now but bear with me) and ease MSW integration into existing projects. A significant portion of the issues people experience with MSW is caused by improperly written request handlers. URL typos, missing parameters, wrong base URLs are common and, luckily, easily solvable reasons. The main difficulty with such issues is to notice them. That's precisely why you see those warnings, as MSW will warn on any unhandled request by default. That being said, there may be requests you don't intend to mock, like those WDS requests. For those, I have a couple of suggestions you can apply. Suggestion 1Explicitly whitelist those requests in the worker.start({
onUnhandledRequest(request) {
// Do not warn on the requests that match the condition below.
if (request.url.href.includes('sockjs-node/info') || request.protocol === 'chrome-extension:') {
return
}
// Warn on any other unhandled requests.
console.warn('Unhandled: %s %s', request.method, request.url.href)
}
}) Suggestion 2Disable the warnings altogether. This may be useful for projects that already have MSW integrated and don't benefit much from these warnings while developing. worker.start({ onUnhandledRequest: 'bypass' }) You can also utilize a request handler that captures those requests but returns no mocked response. Perhaps we could integrate some pre-checks into the library, like ignoring |
Beta Was this translation helpful? Give feedback.
Hey, @adesurirey.
We've enabled the "warn" strategy for all unhandled requests a few minor versions back. The reason for that is to improve developer experience (I know this sounds counter-intuitive right now but bear with me) and ease MSW integration into existing projects.
A significant portion of the issues people experience with MSW is caused by improperly written request handlers. URL typos, missing parameters, wrong base URLs are common and, luckily, easily solvable reasons. The main difficulty with such issues is to notice them. That's precisely why you see those warnings, as MSW will warn on any unhandled request by default.
That being said, there may be requests you don't intend …