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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow forwarding of requests with ctx.forward #962

Closed
wants to merge 1 commit into from

Conversation

mcky
Copy link

@mcky mcky commented Oct 31, 2021

As discussed in #234 and #676 (Add "ctx.forward" for forwarding (bypassing) requests) this adds a ctx.forward() method.

The new API looks like

rest.get('/user', (req, res, ctx) => {
  if (anything) {
    return res(ctx.forward())
  }

  return res(ctx.text('mocked'))
})

It differs slightly to the suggestion in #676 as it wraps the forward call in res() - if that's a deal breaker I can try to figure out how to implement it as per the issue

The behaviour is exactly the same as a x-msw-bypass header or returning undefined, just without the warnings.

Happy with any and all feedback - for now I've hacked in a x-msw-bypass into my own test-suite just to silence the undefined warnings 馃槄

Todo:

  • Update documentation

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 42d4ed5:

Sandbox Source
MSW React Configuration

@kettanaito
Copy link
Member

Hey, @mcky. Thank you so much for your work on this feature. I've decided to go with #1204.

@mcky
Copy link
Author

mcky commented Apr 13, 2022

Hey, @mcky. Thank you so much for your work on this feature. I've decided to go with #1204.

Glad to see a solution is in either way!

@kettanaito
Copy link
Member

Released: v0.40.0 馃帀

This has been released in v0.40.0!

Make sure to always update to the latest version (npm i msw@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

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