Skip to content

Commit c495537

Browse files
Copilotkarpikpl
andauthored
fix: initialize proxy agent in sync-entry.ts to respect HTTP_PROXY (#347)
* Initial plan * fix: initialize proxy agent in sync-entry.ts to respect HTTP_PROXY env var Agent-Logs-Url: https://github.com/github-copilot-resources/copilot-metrics-viewer/sessions/2952bbf5-4bc5-44c2-9a5f-b1c7ae31aad1 Co-authored-by: karpikpl <3539908+karpikpl@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: karpikpl <3539908+karpikpl@users.noreply.github.com> Co-authored-by: Piotr Karpala <karpik.pl@gmail.com>
1 parent c29cbd4 commit c495537

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

server/sync-entry.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,36 @@
1212
* - NUXT_GITHUB_TOKEN: GitHub personal access token
1313
* - SYNC_DAYS_BACK: Number of days to sync (default: 28, uses bulk download)
1414
* - DATABASE_URL: PostgreSQL connection string (or use PG* env vars)
15+
* - HTTP_PROXY: Optional HTTP/HTTPS proxy URL (e.g. http://proxy:8080)
16+
* - CUSTOM_CA_PATH: Optional path to a custom CA certificate file
1517
*/
1618

19+
// Initialize proxy agent before any fetch calls (mirrors server/plugins/http-agent.ts)
20+
import { ProxyAgent, setGlobalDispatcher } from 'undici';
21+
import { readFileSync, existsSync } from 'fs';
22+
23+
if (process.env.HTTP_PROXY) {
24+
try {
25+
const tlsOptions = process.env.CUSTOM_CA_PATH ? (() => {
26+
if (!existsSync(process.env.CUSTOM_CA_PATH!)) {
27+
throw new Error(`CUSTOM_CA_PATH file not found: ${process.env.CUSTOM_CA_PATH}`);
28+
}
29+
return { tls: { ca: [readFileSync(process.env.CUSTOM_CA_PATH!)] } };
30+
})() : {};
31+
32+
const proxyAgent = new ProxyAgent({
33+
uri: process.env.HTTP_PROXY,
34+
...tlsOptions
35+
});
36+
37+
setGlobalDispatcher(proxyAgent);
38+
console.info(`Proxy agent initialized: ${process.env.HTTP_PROXY}`);
39+
} catch (error) {
40+
console.error('Failed to initialize proxy agent:', error);
41+
process.exit(1);
42+
}
43+
}
44+
1745
import { syncBulk } from './services/sync-service';
1846
import { initSchema } from './storage/db';
1947
import { closePool } from './storage/db';

0 commit comments

Comments
 (0)