Support passing agent option in fetch for proxy use cases (with Next.js fetch layer) #81916
Unanswered
jdladiana86
asked this question in
App Router
Replies: 2 comments 2 replies
-
+1 I was searching for this. Another use case (my case) it is to use custom certificates, which some servers I need to fetch requires me to. Like so: const agent = new https.Agent({
cert: process.env.SOME_CERT,
key: process.env.SOME_KEY,
});
await fetch("https://some-site.com", {
next: {
agent: agent,
}
}); |
Beta Was this translation helpful? Give feedback.
0 replies
-
I also need the proxy support. Is there doc about nextjs fetch? I thought it was the native server fetch in nodejs... |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Currently, Next.js overrides the global
fetch
implementation to add caching, revalidation, and streaming support. However, this fetch layer does not allow passing anagent
option, which is necessary when working with proxy agents (e.g.https-proxy-agent
) in some environments.This makes it impossible to use Next.js's enhanced fetch and proxy HTTP requests at the same time.
Why it's needed
I have a real-world use case where:
fetch
caching features (next.revalidate
, deduplication, etc.)At the moment, I’m forced to either:
globalThis.fetch
ornode-fetch
, which allowsagent
but loses Next.js featuresNext.js fetch
, but lose the ability to configure a proxy agentThis is a blocker for some production setups, especially in enterprise environments.
Suggested solution
It would be helpful to either:
agent
option directly (if possible)next
config key, e.g.:Beta Was this translation helpful? Give feedback.
All reactions