mirror of
https://github.com/koala73/worldmonitor.git
synced 2026-04-26 01:24:59 +02:00
* fix(seed-economy): use gate.decodo.com for FRED CONNECT proxy, add fallback logging resolveProxyString() replaces gate. → us.decodo.com for curl compatibility, but httpsProxyFetchJson uses HTTP CONNECT tunneling which requires gate.decodo.com. All FRED series were silently failing with "Parse Error: Expected HTTP/, RTSP/ or ICE/" because us.decodo.com doesn't respond to CONNECT with valid HTTP. - Add resolveProxyStringConnect() in _proxy-utils.cjs (no host replacement) - Export resolveProxyForConnect() from _seed-utils.mjs for CONNECT-based proxy - seed-economy: _proxyAuth uses resolveProxyForConnect() (FRED), _curlProxyAuth uses resolveProxy() (Yahoo) - fredFetchJson now logs when direct fails and proxy is tried, labels proxy errors as "proxy: ..." * fix(seed-economy): roll out resolveProxyForConnect to all FRED seeders seed-economic-calendar, seed-supply-chain-trade, and seed-bls-series were still passing the curl-oriented us.decodo.com proxy string to fredFetchJson, which uses HTTP CONNECT tunneling and requires gate.decodo.com.
94 lines
3.1 KiB
JavaScript
94 lines
3.1 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Shared proxy configuration parser used by ais-relay.cjs and _seed-utils.mjs.
|
|
*
|
|
* Supported formats for PROXY_URL:
|
|
* - http://user:pass@host:port (standard URL)
|
|
* - host:port:user:pass (Decodo/Smartproxy)
|
|
*
|
|
* Returns { host, port, auth: 'user:pass' } or null.
|
|
*/
|
|
function parseProxyConfig(raw) {
|
|
if (!raw) return null;
|
|
|
|
// Standard URL format: http://user:pass@host:port or https://user:pass@host:port
|
|
try {
|
|
const u = new URL(raw);
|
|
if (u.hostname) {
|
|
return {
|
|
host: u.hostname,
|
|
port: parseInt(u.port, 10),
|
|
auth: u.username ? `${decodeURIComponent(u.username)}:${decodeURIComponent(u.password)}` : null,
|
|
tls: u.protocol === 'https:',
|
|
};
|
|
}
|
|
} catch { /* fall through */ }
|
|
|
|
// Froxy/OREF format: user:pass@host:port
|
|
if (raw.includes('@')) {
|
|
const atIdx = raw.lastIndexOf('@');
|
|
const auth = raw.slice(0, atIdx);
|
|
const hostPort = raw.slice(atIdx + 1);
|
|
const colonIdx = hostPort.lastIndexOf(':');
|
|
if (colonIdx !== -1) {
|
|
const host = hostPort.slice(0, colonIdx);
|
|
const port = parseInt(hostPort.slice(colonIdx + 1), 10);
|
|
if (host && port && auth) return { host, port, auth };
|
|
}
|
|
}
|
|
|
|
// Decodo/Smartproxy format: host:port:user:pass
|
|
const parts = raw.split(':');
|
|
if (parts.length >= 4) {
|
|
const host = parts[0];
|
|
const port = parseInt(parts[1], 10);
|
|
const user = parts[2];
|
|
const pass = parts.slice(3).join(':');
|
|
if (host && port && user) return { host, port, auth: `${user}:${pass}` };
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Resolve proxy from PROXY_URL only. Returns { host, port, auth } or null.
|
|
* Use this for sources where OREF (IL-exit) proxy must NOT be used (e.g. USNI).
|
|
*/
|
|
function resolveProxyConfig() {
|
|
return parseProxyConfig(process.env.PROXY_URL || '');
|
|
}
|
|
|
|
/**
|
|
* Resolve proxy from PROXY_URL with fallback to OREF_PROXY_AUTH.
|
|
* Use this for general seeders (fear-greed, disease-outbreaks, etc.).
|
|
*/
|
|
function resolveProxyConfigWithFallback() {
|
|
return parseProxyConfig(process.env.PROXY_URL || process.env.OREF_PROXY_AUTH || '');
|
|
}
|
|
|
|
/**
|
|
* Returns proxy as "user:pass@host:port" string for use with curl -x.
|
|
* Decodo: gate.decodo.com → us.decodo.com (curl endpoint differs from CONNECT endpoint).
|
|
* Returns empty string if no proxy configured.
|
|
*/
|
|
function resolveProxyString() {
|
|
const cfg = resolveProxyConfigWithFallback();
|
|
if (!cfg) return '';
|
|
const host = cfg.host.replace(/^gate\./, 'us.');
|
|
return cfg.auth ? `${cfg.auth}@${host}:${cfg.port}` : `${host}:${cfg.port}`;
|
|
}
|
|
|
|
/**
|
|
* Returns proxy as "user:pass@host:port" string for use with HTTP CONNECT tunneling.
|
|
* Does NOT replace gate.decodo.com → us.decodo.com; CONNECT endpoint is gate.decodo.com.
|
|
* Returns empty string if no proxy configured.
|
|
*/
|
|
function resolveProxyStringConnect() {
|
|
const cfg = resolveProxyConfigWithFallback();
|
|
if (!cfg) return '';
|
|
return cfg.auth ? `${cfg.auth}@${cfg.host}:${cfg.port}` : `${cfg.host}:${cfg.port}`;
|
|
}
|
|
|
|
module.exports = { parseProxyConfig, resolveProxyConfig, resolveProxyConfigWithFallback, resolveProxyString, resolveProxyStringConnect };
|