-
Notifications
You must be signed in to change notification settings - Fork 27.3k
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
not support proxy-agent #47039
Comments
any solutions? |
not yet |
NextJS support proxy just like nodejs https://github.com/Yidadaa/ChatGPT-Next-Web/pull/295/files I extract the core part to here https://github.com/wenerme/wode/blob/main/packages/utils/src/servers/createFetchWithProxyByNextUndici.ts |
an alternative is to use global-agent and cross-fetch/polyfill for dev env setup Remember to setup the GLOBAL_AGENT_HTTP_PROXY etc. |
It does not work with the next version 13 or 14 which uses undici |
Thanks to this comment #66373 (comment) I successfully setup a global proxy agent with no custom server inside the import { ProxyAgent, setGlobalDispatcher } from "undici";
if (process.env.HTTP_PROXY) {
const proxyAgent = new ProxyAgent(process.env.HTTP_PROXY);
setGlobalDispatcher(proxyAgent);
}
export default async function Layout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html >
<body>
{children}
</body>
</html>
);
} |
I was also able to leverage undici + const { ProxyAgent, setGlobalDispatcher } = require('undici');
// ...
const { PROXY_HOST, PROXY_PORT } = process.env;
setGlobalDispatcher(new ProxyAgent(`http://${PROXY_HOST}:${PROXY_PORT}`));
const app = next({ /* ... */ }); |
Good one, I also looking at the instrumentationHook, and use instrumentation.js to set the proxy agent, instead of layout. https://nextjs.org/docs/app/api-reference/next-config-js/instrumentationHook |
Closing as there appear to be working solutions provided above and the original issue does not provide a valid reproduction (and may be out of date as the fetch builtin is Undici which leverages dispatchers). Please feel free to create a new issue following the bug report template if you have a valid reproduction of a bug. |
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: x64 Version: Darwin Kernel Version 17.7.0: Fri Oct 30 13:34:27 PDT 2020; root:xnu-4570.71.82.8~1/RELEASE_X86_64 Binaries: Node: 16.19.1 npm: 8.19.3 Yarn: 1.3.2 pnpm: 7.29.1 Relevant packages: next: 13.2.3 eslint-config-next: 13.2.3 react: 18.2.0 react-dom: 18.2.0
Which area(s) of Next.js are affected? (leave empty if unsure)
No response
Link to the code that reproduces this issue
no
To Reproduce
Describe the Bug
proxy failed and fetch failed
error - Error: The edge runtime does not support Node.js 'events' module.
Expected Behavior
ProxyAgent can proxy correctly rather than report error
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
The text was updated successfully, but these errors were encountered: