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

Add passthrough support #11

Merged
merged 4 commits into from
Nov 9, 2023
Merged

Add passthrough support #11

merged 4 commits into from
Nov 9, 2023

Conversation

IanVS
Copy link
Contributor

@IanVS IanVS commented Aug 11, 2023

This adds support for adding passthroughs to msw from a mirage config.

It's handled a bit similarly to pretender, which uses route-recognizer. This also does, but it builds up a Map of hosts to a Map of verbs to route recognizers. I'm using this in my own app with a pnpm patch, and it seems to work correctly, though it's a bit noisy because MSW tries to handle all requests, even for favicons and other resources on the local host.

There are two main improvements to make still:

  • Support callback passthroughs.
  • Don't warn on unhandled requests to the local dev server.

Not sure if either should be considered blocking on this PR, or we can open an issue to tackle them later since this is at least an improvement.

| 'patch'
| 'delete'
| 'options'
| 'head';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Realized I can just use this from mirage. 😀

@@ -52,6 +44,8 @@ type MirageServer = {
options?: unknown
) => (request: RestRequest) => ResponseData | PromiseLike<ResponseData>;

shouldLog: () => boolean;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm only defining parts of the MirageServer we actually care about / use here, to allow this to be as decoupled from upstream Mirage as possible.

@IanVS
Copy link
Contributor Author

IanVS commented Sep 13, 2023

Alright, this should be ready for review now whenever you have time, @bgantzler. I've implemented passthrough functions, and I'm preventing warning messages for requests for assets like the favicon and other static assets, which can happen during hot module reloading, for instance.

@IanVS
Copy link
Contributor Author

IanVS commented Oct 26, 2023

@cah-brian-gantzler do you have time to review this, or should I just merge it and proceed? I'm fine with either approach, just want to make sure you have a chance to take a look if you want to.

@IanVS IanVS merged commit 4f41456 into master Nov 9, 2023
2 checks passed
@IanVS IanVS deleted the passthrough branch November 9, 2023 15:54
@cah-brian-gantzler
Copy link
Collaborator

Im really out of touch with the MSW stuff. Thanks for doing this and asking, but I wouldnt wait on me (as I see you didnt 😄 )

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

Successfully merging this pull request may close these issues.

None yet

2 participants