-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to prevent msw
from catching some URLs: improve docs?
#90
Comments
Hey @sneko thank you so much for opening this issue! I'll discuss with @kettanaito about it and I'll see if we can improve the documentation. This sounds like a very interesting use case! |
Hey! Thanks for proposing this. I would like to learn more about what you're trying to do. The code snippet you shared above is not going to work and I suspect multiple things are mixed here. I will do my best guessing what they are. How to suppress unhandled request warnings from some resources?Use the initialize({
onUnhandledRequest(request, print) {
if (request.url.pathname === '/some-resource') {
return
}
print.warning()
}
}) Note that MSW won't do anything by default if you provide a function as the value for this option. If you wish to ignore the unhandled requests' warnings, just do an early return in that function and you're all set. How to bypass a request only in some cases?So you have a mock for rest.get('/resource', (req, res, ctx) => {
if (req.url.searchParams.has('someParam')) {
return req.passthrough()
}
// Otherwise, respond with a mock.
return res(ctx.text('Hello world!'))
}) I don't want for a certain resource group to ever be mockedOnce again, you can utilize rest.get('/some-path/*', (req) => {
return req.passthrough()
}) With this, any requests under I think none of these things belong to the add-on's documentation because this is not add-on-specific knowledge. You can find these APIs in the MSW documentation and I'm currently working hard on improving the docs experience. |
It's been some time. I think I just wanted to clarify that in your documentation you deconstructed the input object and at that time I thought it would be useful to see all the possibilities of the parameters You can close this if does not make sense 🚀 Thanks for answering 👍 |
@kettanaito would it be useful from the addon's perspective to provide a default initial handler that does something like: rest.get('/node_modules/*', (req) => {
return req.passthrough()
}) To help with possible HMR clash issues and also to improve performance as a positive side effect? |
@sneko, no worries! I am thankful for your input. @yannbf, I think that wouldn't bring many benefits because you don't typically serve node modules. HMR requests are often those to a running WebSocket server that has nothing related to I would love to ship some defaults not to spam people with warnings on requests that are implementation details of the framework they are using (such as HMR) but the issue is that those requests are precisely that—implementation details. They may change without any notice, and it would be virtually impossible to keep up with how every framework structures their features when it comes to HTTP requests that implement them. But I'm open to suggestions, still. |
Hi,
I looked multiple times at the addon docs but also the main docs and it was not obvious at all from the
initialize()
function I would be able to let pass some specific URLs thanks topassthrough()
:It did not come to mind since https://mswjs.io/docs/api/request/passthrough talks about request, but in the examples https://msw-sb.vercel.app/?path=/story/guides-getting-started--page#configuring-msw it only talks about
method
andurl
.It's maybe not an issue, but I hope it can save some time to others :D
Thank you,
The text was updated successfully, but these errors were encountered: