-
Notifications
You must be signed in to change notification settings - Fork 203
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
[Miniflare 3] Add outboundService
option for customising global fetch()
target
#629
Conversation
|
Omg. I added so much custom code to emulate this. If I'd know I would have asked for this sooner. LGTM |
Note that this setting affects more than just fetch() -- it will also affect where connect() goes, and would presumably affect similar functions that we add in the future. Hence why the setting in What you want to name it is up to you but just wanted to make sure this was understood. |
@mrbbot is there a way to make it easier to have a |
Ah good to know, thanks! Will rename to @vlovich something like... new Miniflare({
async outboundService(request) {
return new Response(...)
}
}) Could definitely make it accept any service designator similar to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Total bike shedding, but why the change in name from globalOutbound
?
`workerd` exposes a `globalOutbound` option for customising which service global `fetch()` calls should be dispatched to. For tests, it's useful to be able to mock responses to certain routes or assert certain requests are made. This new option allows `fetch()` call to be sent to another configured Worker. See the added test for an example. Note support for `undici`'s `MockAgent` API in Miniflare 3 is still planned. This is a lower-level primitive for customising `fetch()` responses.
30b0b47
to
edaef43
Compare
fetchService
option for customising global fetch()
targetoutboundService
option for customising global fetch()
target
@penalosa wanted the name to include |
This builds on top of #629, adding back support for `undici` `MockAgent`s (https://undici.nodejs.org/#/docs/api/MockAgent) via the `fetchMock` option. This makes it easy to mock outbound `fetch()` requests in tests. This API is the same as Miniflare 2.
Has this feature landed in the latest release yet? The documentation on NPM already contains the |
Hey! 👋 This should've been released as part of |
I doubled checked and turns out I was missing some bindings and fetch is just failing instead. Sorry another question though, is it possible to filter which request get passed to the Edit: NVM, I can just return a direct fetch response from the outboundService function. It's not fully the same as coming from Miniflare itself but I'll chalk up any difference to problems with API client libraries I'm using. |
This builds on top of #629, adding back support for `undici` `MockAgent`s (https://undici.nodejs.org/#/docs/api/MockAgent) via the `fetchMock` option. This makes it easy to mock outbound `fetch()` requests in tests. This API is the same as Miniflare 2.
workerd
exposes aglobalOutbound
option for customising which service globalfetch()
calls should be dispatched to. For tests, it's useful to be able to mock responses to certain routes or assert certain requests are made. This new option allowsfetch()
call to be sent to another configured Worker. See the added test for an example.Note support for
undici
'sMockAgent
API in Miniflare 3 is still planned. This is a lower-level primitive for customisingfetch()
responses./cc @vlovich