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

Set proxy for some fetch request (not all) #1350

Closed
tamaina opened this issue Apr 20, 2022 · 4 comments
Closed

Set proxy for some fetch request (not all) #1350

tamaina opened this issue Apr 20, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@tamaina
Copy link

tamaina commented Apr 20, 2022

I apologize if this has already been implemented or issue created, but I could not find this usage in the documentation.

This would solve...

I would like to specify a proxy for each fetch run.

The implementation should look like...

Deno implements as follows PR:
denoland/deno#10907

In undici, it would become as follows...?

import { ProxyAgent } from 'undici';

const client = new ProxyAgent('localhost:3000');
const response = await fetch("https://myserver.com", { client });

(Is ProxyAgent better than Client?)

@mcollina
Copy link
Member

cc @ronag

@KhafraDev
Copy link
Member

import { ProxyAgent } from 'undici';

const client = new ProxyAgent('localhost:3000');
const response = await fetch("https://myserver.com", {
    dispatcher: client
});

If you are using node v18.2.0 or above, this will work using node's fetch. Otherwise, you need to import fetch from undici on v5.2.0 or above.

@1999
Copy link

1999 commented Aug 20, 2024

@KhafraDev sorry for reviving this thread, but is this a standard thing? I couldn't find any "dispatcher" in Fetch API docs. It also isn't listed in Typescript "lib" types for "RequestInit":

image

@KhafraDev
Copy link
Member

It's a node-specific extension. I wouldn't recommend using the dom types in node; @types/node will be more correct.

https://github.com/nodejs/undici?tab=readme-ov-file#undicifetchinput-init-promise

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

4 participants