Replacing JsonServiceClient's usage of fetch

Is there a way to not use fetch and use another http client library/method on JsonServiceClient, so we can override the Host header (which is not possible startin from node 18.8.2, according to Node 18.18.2 : unable to override the Host header in fetch · Issue #50305 · nodejs/node · GitHub )?

For context: we’re using the typescript version of JsonServiceClient on a NextJS frontend for a .Net multi-tenant application. Each tenant has a different host.

There is:

  • nextjs code running on the browser on the client, calling the backend api
  • nextjs code running on the nodejs server, calling the backend api

The nodejs server lives on the same machine as the .Net application, and calls the backend api via 127.0.0.1, overriding the Host header with the correct host for the request tenant. As of NodeJS 18.8.2, this is no longer allowed, with the indication to use Undici.request, for example.

Calling the backend via the host would send the request back out of the server to to load balancer, etc etc. Using a split dns configuration to point the host to 127.0.0.1 on the server is something we very much would like to avoid.

You could always monkey patch and replace the default window.fetch or globalThis.fetch with your own implementation which may not be viable if you have other libraries relying on the default impl.

Alternatively you can maintain a local copy of servicestack/client/index.ts in your project and use that. It’s a single file with no external dependencies so should be an easy drop in any project.

Thanks for the quick response, we’ll look at both options.