-
-
Notifications
You must be signed in to change notification settings - Fork 536
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
allow passthrough for undefined routes / graphql interferes with passthrough #234
Comments
In particular I'm having trouble with auth0 and jwt token verification... if I mock it the jwt can't be verified... otherwise it seems like I need to setup SSL certificate for my local development to be on HTTPS in order to be able to fetch downstream auth0? An auth0 recipe may be helpful. |
Hey, @ilovett. Thanks for raising this. Just to clarify: if your response resolver doesn't return anything, that request will be bypassed, even if it matches a predicate. To illustrate, this should log out each GET request your app makes, while performing them as-is: rest.get('*', (req, res, ctx) => {
console.log(req.url.href)
// Notice no `return res()` statement
}) You can utilize that behavior to conditionally short circuit in a resolver: res.get('/auth', (req, res, ctx) => {
if (someCondition) {
// Return nothing, thus, bypassing this request
return null
}
// Return a mocked response
return res(...)
}) Also, any request that does not have a corresponding request handler is performed passthrough by default. If I understand correctly, the absence of a request handler is what you mean by "for undefined routes". Did I get it correctly? (It would be very helpful if you included an example of what you are talking about, even if in pseudo-code).
A good point 👍 We may have to list such recipe on the docs. Perhaps, even as an outcome of our discussion here! |
Thanks @kettanaito ! Yes looks like I was also searching for "passthrough" and not "bypass" :( returning nothing definitely works! -- although I did not understand this from the docs, and also I get type errors using your solution -- I got around it by: (rest as any).post('https://my.auth0.com/oauth/token', () => {
return;
}), Here's the type error with using
A couple things about the docs:
I might also make it a default option on Returning nothing to bypass was not clear to me -- I thought I needed to To answer your Q:
Yes, undefined routes might automatically be allowed passthrough based on that config setting. Similar to IE if absent handlers, then allow the original request to go through |
Docs at https://redd.gitbook.io/msw is the previous version. I highly recommend to use https://mswjs.io, as it's the latest (and the only) maintained docs now. It's also been largely rewritten and contains up-to-date information.
My bad, try using At this point I'm confused what's the difference between bypassing and passthrough. Don't they both mean "perform request as-is and do not mock"?
Note that having a handler like this is redundant: rest.get('/path', (req, res, ctx) => {
return
}) It's absolutely the same as not having that handler at all (remove it and see what happens). What I'm trying to say, is that if you don't have any Sorry, I think I still don't fully understand the problem. Could you elaborate more, what exactly is the current setup, the problem (behavior/errors/etc.), and what's the expected behavior? |
Yes
No problem, but we would need to add
When I comment out the handlers I get 500 errors on my auth0 and sentry... (but work as expected with void handlers)
Here's my config:
I am on |
I'm running into a similar issue - I've enabled a GraphQL handler, and I'm now getting errors trying to do POSTS to my authentication server (using REST). I'm getting this error:
which looks like it's coming from the |
Hy guys I understand your problem. Requests without a specific handler throw that error. At the moment you cannot pass through a request without defining an handler for that request. For me it can be considered a bug, I think is not correct to return that error in this case, maybe a warning should be better. What do you think @kettanaito ? |
Since a GraphQL request is still a regular HTTP request (GET/POST with a certain query/body according to the GraphQL specification), one cannot distinguish the two, unless a more narrow match is performed. The issue you are experiencing is most likely when a What interests me, is that |
OK I think I figured it out. Sorry, in my snippet I did not include my graphql queries as I thought it was irrelevant for simplicity. But yes, I did have some graphql queries defined. I think if any graphql queries are defined, then that interferes with the "not defined" pass through because it must be listening to "every (other) request" and so in that case, not defining won't work. |
@kettanaito I could use this feature as well for testcafe support. testcafe has some internal posts it makes back to it's proxy server, and we can't add headers to those requests. I noticed that if i just add |
Please, could you update on the latest state of this issue? Is it still reproducible? If yes, please, could you set up a reproduction repository for us to look? Thank you. |
I believe this issue is caused by the request handler lookup mechanism internally. We are tackling it as a part of #258. |
@ilovett, hi. Could you please update to |
@kettanaito Unfortunately I can't use
I get these errors:
I was able to get |
thanks @kettanaito , just upgraded to |
Describe the solution you'd like
I'd like to be able to allow certain matching urls to be passed through and handled normally instead of intercepting and giving 404.
Describe alternatives you've considered
Seems like a lot of work to manually define
ctx.fetch
for each request I would want to pass through on some wildcard domain / string match.The text was updated successfully, but these errors were encountered: