raycast-multi-translate icon indicating copy to clipboard operation
raycast-multi-translate copied to clipboard

Does it need a proxy?

Open horaoen opened this issue 2 years ago • 1 comments

I have configured global proxy, but it seems not work.

horaoen avatar Jun 12 '23 06:06 horaoen

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

tmkx avatar Jun 12 '23 11:06 tmkx

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

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.

horaoen avatar Jun 14 '23 01:06 horaoen

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.

tmkx avatar Jun 14 '23 03:06 tmkx

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.

ok, i'll think about how to do it. I have defined setpxy in .zshrc image

horaoen avatar Jun 14 '23 03:06 horaoen

你才是真正的英雄

hechunfeng123 avatar Jun 14 '23 05:06 hechunfeng123