2026-02-28 10:11:53 +07:00
|
|
|
import { getSettings } from "@/lib/localDb";
|
|
|
|
|
import { applyOutboundProxyEnv } from "@/lib/network/outboundProxy";
|
|
|
|
|
|
|
|
|
|
let initialized = false;
|
|
|
|
|
|
|
|
|
|
export async function ensureOutboundProxyInitialized() {
|
|
|
|
|
if (initialized) return true;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const settings = await getSettings();
|
|
|
|
|
applyOutboundProxyEnv(settings);
|
|
|
|
|
initialized = true;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("[ServerInit] Error initializing outbound proxy:", error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return initialized;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-09 17:48:20 +07:00
|
|
|
// Defer init so HTTP server accepts connections first
|
|
|
|
|
setImmediate(() => {
|
|
|
|
|
ensureOutboundProxyInitialized().catch(console.log);
|
|
|
|
|
});
|
2026-02-28 10:11:53 +07:00
|
|
|
|
|
|
|
|
export default ensureOutboundProxyInitialized;
|