api/env: update proxy envs when changed in env file

This commit is contained in:
jj
2025-07-19 16:04:21 +00:00
parent 3c5f5b90b2
commit 00b2a8f085
3 changed files with 30 additions and 4 deletions

View File

@@ -10,6 +10,10 @@ import { Green, Yellow } from "../misc/console-text.js";
const forceLocalProcessingOptions = ["never", "session", "always"];
const youtubeHlsOptions = ["never", "key", "always"];
const httpProxyVariables = ["NO_PROXY", "HTTP_PROXY", "HTTPS_PROXY"].flatMap(
k => [ k, k.toLowerCase() ]
);
const changeCallbacks = {};
const onEnvChanged = (changes) => {
@@ -43,6 +47,18 @@ export const loadEnvs = (env = process.env) => {
}
}));
// we need to copy the proxy envs (HTTP_PROXY, HTTPS_PROXY)
// back into process.env, so that EnvHttpProxyAgent can pick
// them up later
for (const key of httpProxyVariables) {
const value = env[key] ?? canonicalEnv[key];
if (value !== undefined) {
process.env[key] = env[key];
} else {
delete process.env[key];
}
}
return {
apiURL: env.API_URL || '',
apiPort: env.API_PORT || 9000,
@@ -79,6 +95,9 @@ export const loadEnvs = (env = process.env) => {
externalProxy: env.API_EXTERNAL_PROXY,
// used only for comparing against old values when envs are being updated
httpProxyValues: httpProxyVariables.map(k => String(env[k])).join(''),
turnstileSitekey: env.TURNSTILE_SITEKEY,
turnstileSecret: env.TURNSTILE_SECRET,
jwtSecret: env.JWT_SECRET,
@@ -202,7 +221,8 @@ const wrapReload = (contents) => {
for (const key of changes) {
const value = currentEnv[key];
const isSecret = key.toLowerCase().includes('apikey')
|| key.toLowerCase().includes('secret');
|| key.toLowerCase().includes('secret')
|| key === 'httpProxyValues';
if (!value) {
console.log(` removed: ${key}`);