Cannot combine handling and passthrough for the same resource
See original GitHub issueWhat I need to achieve is to only handle a few of my endpoints with MirageJS (to get certain responses in my e2e tests) and have all other requests pass through to my actual API.
The empty passthrough()
function, as suggested in the docs, didn’t work for me at all, but using a function that compares the request.url
and request.method
with the routes I am handling in MirageJS and returning true
for all other requests does the trick. So far, so good.
The issue now is that I need to catch PUT
requests to https://api.myapp.com/user
in MirageJS, but let GET
requests to that same url pass through. This gives me the error this.put() is not a function
when the PUT
request is sent (not during setup). The GET
request, which is sent first, is being passed through as it should. I tried to solve this in several ways, including this.resource('user', { only: ['update'] })
but to no avail.
The only way I got this working is by also handling the GET
request with MirageJS – which is not what I want because it means I’d have to copy the exact response from my actual API.
Here is my latest, not working setup:
window.server = new Server({
routes() {
this.urlPrefix = 'https://api.myapp.com';
this.resource('user');
this.put('/user', () => console.log('put user with mirage'));
this.passthrough(request => {
if (request.url === 'https://api.myapp.com/user' && request.method === 'PUT') {
return false;
}
return true;
});
},
});
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
Ok sorry about that - closing for now but feel free to drop more comments if you run into anything! And keep an eye out for new passthrough API hopefully coming soon.
Really sorry, but I don’t have time for that and am not allowed to share the repo I am working on… Wish I could be more helpful! 😕
I’ll just stick with my workaround for now – feel free to close this issue if you want.