Does it need a proxy?
I have configured global proxy, but it seems not work.
Node.js will send requests directly by default.
solution 1: https://www.google.com/search?q=clash+enhanced+mode
solution 2:
pnpm add undici
src/translate.tsx
+import { ProxyAgent, setGlobalDispatcher } from 'undici'
import { Main } from './components/Main'
+const agent = new ProxyAgent({
+ uri: 'http://127.0.0.1:7890',
+})
+
+setGlobalDispatcher(agent)
+
export default Main
Node.js will send requests directly by default.
solution 1: https://www.google.com/search?q=clash+enhanced+mode
solution 2:
pnpm add undicisrc/translate.tsx
+import { ProxyAgent, setGlobalDispatcher } from 'undici' import { Main } from './components/Main' +const agent = new ProxyAgent({ + uri: 'http://127.0.0.1:7890', +}) + +setGlobalDispatcher(agent) + export default Main
Thanks a lot, for solution 1, my clash's version does not support, for solution 2, I think this is an elegant solution by dynamically reading the proxy environment variables($http_proxy, $https_proxy, $all_proxy) of the terminal to adjust above code.
browsers will follow the system's proxy config, but terminals and other apps may not. for example, you need to declare env vars in shell config files like .bashrc to work for a terminal session, it will not exist unless you define it, so that we can't read http_proxy in raycast extension. in app, you can get system global proxy config by scutil --proxy.
by the way, the solution 2 is a temporary workaround for @iamtraction/google-translate which is using undici as its request library.
browsers will follow the system's proxy config, but terminals and other apps may not. for example, you need to declare env vars in shell config files like
.bashrcto work for a terminal session, it will not exist unless you define it, so that we can't readhttp_proxyin raycast extension. in app, you can get system global proxy config byscutil --proxy.by the way, the solution 2 is a temporary workaround for
@iamtraction/google-translatewhich is usingundicias its request library.
ok, i'll think about how to do it. I have defined setpxy in .zshrc
你才是真正的英雄