Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 00b2a8f

Browse files
api/env: update proxy envs when changed in env file
1 parent 3c5f5b9 commit 00b2a8f

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

‎api/src/config.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { loadEnvs, validateEnvs } from "./core/env.js";
33

44
const version = await getVersion();
55

6+
const canonicalEnv = Object.freeze(structuredClone(process.env));
67
const env = loadEnvs();
78

89
const genericUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36";
910
const cobaltUserAgent = `cobalt/${version} (+https://github.com/imputnet/cobalt)`;
1011

11-
export const canonicalEnv = Object.freeze(structuredClone(process.env));
1212
export const setTunnelPort = (port) => env.tunnelPort = port;
1313
export const isCluster = env.instanceCount > 1;
1414
export const updateEnv = (newEnv) => {
@@ -35,6 +35,7 @@ await validateEnvs(env);
3535

3636
export {
3737
env,
38+
canonicalEnv,
3839
genericUserAgent,
3940
cobaltUserAgent,
4041
}

‎api/src/core/api.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,15 @@ export const runAPI = async (express, app, __dirname, isPrimary = true) => {
337337
randomizeCiphers();
338338
setInterval(randomizeCiphers, 1000 * 60 * 30); // shuffle ciphers every 30 minutes
339339

340-
env.subscribe('externalProxy', () => {
340+
env.subscribe(['externalProxy','httpProxyValues'], () => {
341341
// TODO: remove env.externalProxy in a future version
342+
const options = {};
343+
if (env.externalProxy) {
344+
options.httpProxy = env.externalProxy;
345+
}
346+
342347
setGlobalDispatcher(
343-
new EnvHttpProxyAgent({httpProxy: env.externalProxy||undefined})
348+
new EnvHttpProxyAgent(options)
344349
);
345350
});
346351

‎api/src/core/env.js‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import { Green, Yellow } from "../misc/console-text.js";
1010
const forceLocalProcessingOptions = ["never", "session", "always"];
1111
const youtubeHlsOptions = ["never", "key", "always"];
1212

13+
const httpProxyVariables = ["NO_PROXY", "HTTP_PROXY", "HTTPS_PROXY"].flatMap(
14+
k => [ k, k.toLowerCase() ]
15+
);
16+
1317
const changeCallbacks = {};
1418

1519
const onEnvChanged = (changes) => {
@@ -43,6 +47,18 @@ export const loadEnvs = (env = process.env) => {
4347
}
4448
}));
4549

50+
// we need to copy the proxy envs (HTTP_PROXY, HTTPS_PROXY)
51+
// back into process.env, so that EnvHttpProxyAgent can pick
52+
// them up later
53+
for (const key of httpProxyVariables) {
54+
const value = env[key] ?? canonicalEnv[key];
55+
if (value !== undefined) {
56+
process.env[key] = env[key];
57+
} else {
58+
delete process.env[key];
59+
}
60+
}
61+
4662
return {
4763
apiURL: env.API_URL || '',
4864
apiPort: env.API_PORT || 9000,
@@ -79,6 +95,9 @@ export const loadEnvs = (env = process.env) => {
7995

8096
externalProxy: env.API_EXTERNAL_PROXY,
8197

98+
// used only for comparing against old values when envs are being updated
99+
httpProxyValues: httpProxyVariables.map(k => String(env[k])).join(''),
100+
82101
turnstileSitekey: env.TURNSTILE_SITEKEY,
83102
turnstileSecret: env.TURNSTILE_SECRET,
84103
jwtSecret: env.JWT_SECRET,
@@ -202,7 +221,8 @@ const wrapReload = (contents) => {
202221
for (const key of changes) {
203222
const value = currentEnv[key];
204223
const isSecret = key.toLowerCase().includes('apikey')
205-
|| key.toLowerCase().includes('secret');
224+
|| key.toLowerCase().includes('secret')
225+
|| key === 'httpProxyValues';
206226

207227
if (!value) {
208228
console.log(` removed: ${key}`);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /