Skip to content
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

passthrough not really working as expected #1072

Open
maapteh opened this issue Dec 21, 2022 · 9 comments
Open

passthrough not really working as expected #1072

maapteh opened this issue Dec 21, 2022 · 9 comments

Comments

@maapteh
Copy link

maapteh commented Dec 21, 2022

Hi, i understand MirageJS uses Pretender globally which means it basically takes over fetch. But i assumed the passtrough option described here https://miragejs.com/api/classes/server/#passthrough would actually allow other urls to work. Which they don't, the only thing this feature seems to do is to not throw any error.

How can you allow some urls to work? Because i just used it to first create the app without any backend and slowly allow created backend api endpoints to work, by removing them from the mock. But now its an all or nothing implementation ...

Isn't it an idea to let passtrough values use the real fetch?

@cah-brian-gantzler
Copy link
Collaborator

I have not had to write a pretender passthru for other URLs, so no experience, sorry, perhaps someone else has?

Since this repo is using Pretender and pretender is not performing passthru as expected, it would seem this is more an issue for the PretenderJS library (https://github.com/pretenderjs/pretender#pass-through)

Here is some comments in the MirageJS code that talks about passthru https://github.com/miragejs/miragejs/blob/master/lib/mock-server/pretender-config.js#L391.

It looks like while calling the passthru the _getFullPath is being applied https://github.com/miragejs/miragejs/blob/master/lib/mock-server/pretender-config.js#L464, maybe you need to set urlPrefix and namespace to undefined first looking at the fullPath code https://github.com/miragejs/miragejs/blob/master/lib/mock-server/pretender-config.js#L479

@maapteh
Copy link
Author

maapteh commented Dec 21, 2022

The only thing i saw was this logline: https://github.com/miragejs/miragejs/blob/master/lib/mock-server/pretender-config.js#L309-L310
But i do see https://github.com/miragejs/miragejs/blob/master/__tests__/external/browser-only/passthrough-test.js#L41 which makes me think maybe i have config error. Unfortunately i have moved to a setup with an express mock server, but will try to go to old version with mirage and see if i can find more intell.

@maapteh maapteh changed the title passtrough not really working as expected passthrough not really working as expected Dec 21, 2022
@maapteh
Copy link
Author

maapteh commented Dec 22, 2022

I can confirm this issue was about the missing namespace :(
Not documented but in the error log :)

Thanks Brian!

@maapteh maapteh closed this as completed Dec 22, 2022
@maapteh maapteh reopened this Jan 3, 2023
@maapteh
Copy link
Author

maapteh commented Jan 3, 2023

So it lets passthrough the call, but its not actually returning the data using fetch/axios. Which makes the setup unusable when you want to go slowly from a complete mock to a working api application. I guess that should be documented somewhere @cah-brian-gantzler ?

@cah-brian-gantzler
Copy link
Collaborator

When a package is using another package, its really hard to determine what should be documented where. Since the passthru is just calling the pretender passthru, then any issues or nuances should really be documented in pretender.

@alioshr
Copy link

alioshr commented Jun 24, 2023

It is really scary to see that mirage.js is being built over an unmaintained package like pretender.js. And the interesting thing is that pretender.js is quite small, just a few files.

What is the sense is having a behavior that we need to map all request domains to ensure that they do not break? It should be the opposite. Mirage.js should ensure that all requests pass, except for those that we explicitly mock.

We have a use case that our BE is till being architected and we want to start working on UI. But our app is built over a complex infra and many underlying requests are made to different apis / vendors. I have tried it out and could not get it through. Then when I though about the headache in maintaining this while the prototyping phase is done I had to give up.

Is it on the roadmap to abandon pretender.js? If not, I guess that the foundations of this initiative might be on the wrong direction.

@IanVS
Copy link
Collaborator

IanVS commented Jul 5, 2023

@alioshr there is currently a way to swap out pretender for MSW. It's experimental, though, and I haven't yet tried it out. #1037

@alioshr
Copy link

alioshr commented Jul 24, 2023

Hi @IanVS . I have opted in using MSW, just in our testing/staging env. Not registering msw in production. It works pretty well, for our needs on this phase.

But I guess that with some tweaks to mimic some real network behavior for rest api calls, I guess that I would prefer a solution to not rely on service workers, as they are very fragile, as they are restricted by browsers on different conditions (anonymous tabs, etc, vendors, etc).

Of course, for prototyping, we could assume that this issue is not the end of the world, but it limits testing the FE features in diversified browsers, etc. The tradeoff is still positive, imho.

@IanVS
Copy link
Collaborator

IanVS commented Jul 27, 2023

@alioshr thanks for the update. Are you using MSW together with mirage, or on its own? I've hit my own passthrough error in pretender just now, so I might be following in your footsteps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants