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

Use custom fetch(er) for the web client #315

Open
arfath-linklet opened this issue Sep 13, 2024 · 1 comment
Open

Use custom fetch(er) for the web client #315

arfath-linklet opened this issue Sep 13, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@arfath-linklet
Copy link

Use case

By default the web client uses the global fetch. The idea is to configure the client with a custom fetch(er) that may decorate the fetch function with additional functionality. A use case for this could be -

Using mTLS: Cloudflare Workers can use mTLS with added bindings, the binding exposes a fetch(er) with mTLS pre-configured

Describe the solution you'd like

  const client = createClient({
    // A custom fetcher with decorated functionality, in this case a Cloudflare Worker binding with a fetcher preconfigured with mTLS
    fetcher: cloudflareEnv.MY_CERT.fetch
  })

Additional context

https://developers.cloudflare.com/workers/runtime-apis/bindings/mtls

@arfath-linklet arfath-linklet added the enhancement New feature or request label Sep 13, 2024
@slvrtrn
Copy link
Contributor

slvrtrn commented Sep 26, 2024

@arfath-linklet, would you like to contribute to the project and create a PR for it? The implementation is rather trivial:

Add fetch? to

export type WebClickHouseClientConfigOptions =
  BaseClickHouseClientConfigOptions & {
    fetch?: typeof fetch
  }

You'll only need to double-check if the signature is compatible with that cloudflareEnv.MY_CERT.fetch like that right away. Then it just needs to be passed to the WebConnection and used instead of the default one there, if it is defined (see WebImpl in the same config.ts file).

If you have more questions, you can always DM me in the community Slack or comment here.

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

No branches or pull requests

2 participants