working on proxy service

This commit is contained in:
Bojan Kucera 2025-06-07 16:24:27 -04:00
parent 1395e448b7
commit 3d9eb2ec9b
3 changed files with 88 additions and 87 deletions

View file

@ -14,7 +14,9 @@ export class HttpClient {
constructor(config: HttpClientConfig = {}, logger?: Logger) {
this.config = config;
this.logger = logger;
this.logger = logger?.child({
component: 'http',
});
}
// Convenience methods
@ -41,7 +43,6 @@ export class HttpClient {
*/
async request<T = any>(config: RequestConfig): Promise<HttpResponse<T>> {
const finalConfig = this.mergeConfig(config);
this.logger?.debug('Making HTTP request', {
method: finalConfig.method,
url: finalConfig.url,
@ -79,7 +80,7 @@ export class HttpClient {
const timeout = config.timeout ?? this.config.timeout ?? 30000;
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), timeout);
try {
const response = useBunFetch
? await this.fetchRequest<T>(config, controller.signal)
@ -106,7 +107,13 @@ export class HttpClient {
*/
private async fetchRequest<T>(config: RequestConfig, signal: AbortSignal): Promise<HttpResponse<T>> {
try {
const options = this.buildFetchOptions(config, signal);
// const options = this.buildFetchOptions(config, signal);
const options = config.proxy? { proxy: config.proxy?.protocol + '://' + config.proxy?.host + ':' + config.proxy?.port } : {}//this.buildGotOptions(config, signal);
this.logger?.error('Making request with fetch',{url: config.url, options })
const response = await fetch(config.url, options);
return this.parseFetchResponse<T>(response);
@ -121,6 +128,7 @@ export class HttpClient {
private async gotRequest<T>(config: RequestConfig, signal: AbortSignal): Promise<HttpResponse<T>> {
try {
const options = this.buildGotOptions(config, signal);
const response = await got(config.url, options);
return this.parseGotResponse<T>(response);
@ -146,6 +154,7 @@ export class HttpClient {
signal,
};
// Add body
if (config.body && config.method !== 'GET') {
if (typeof config.body === 'object') {