@@ -5,6 +5,7 @@ import { Env, Snapshot, ProcessedSnapshot, Git, Build, Context } from '../types.
55import constants from './constants.js' ;
66import type { Logger } from 'winston'
77import pkgJSON from './../../package.json'
8+ import https from 'https' ;
89
910export default class httpClient {
1011 axiosInstance : AxiosInstance ;
@@ -13,15 +14,38 @@ export default class httpClient {
1314 username : string ;
1415 accessKey : string ;
1516
16- constructor ( { SMARTUI_CLIENT_API_URL , PROJECT_TOKEN , PROJECT_NAME , LT_USERNAME , LT_ACCESS_KEY } : Env ) {
17+ constructor ( { SMARTUI_CLIENT_API_URL , PROJECT_TOKEN , PROJECT_NAME , LT_USERNAME , LT_ACCESS_KEY , SMARTUI_API_PROXY , SMARTUI_API_SKIP_CERTIFICATES } : Env ) {
1718 this . projectToken = PROJECT_TOKEN || '' ;
1819 this . projectName = PROJECT_NAME || '' ;
1920 this . username = LT_USERNAME || '' ;
2021 this . accessKey = LT_ACCESS_KEY || '' ;
2122
22- this . axiosInstance = axios . create ( {
23+ let proxyUrl = null ;
24+ try {
25+ // Handle URL with or without protocol
26+ const urlStr = SMARTUI_API_PROXY ?. startsWith ( 'http' ) ?
27+ SMARTUI_API_PROXY : `http://${ SMARTUI_API_PROXY } ` ;
28+ proxyUrl = SMARTUI_API_PROXY ? new URL ( urlStr ) : null ;
29+ } catch ( error ) {
30+ console . error ( 'Invalid proxy URL:' , error ) ;
31+ }
32+ const axiosConfig : any = {
2333 baseURL : SMARTUI_CLIENT_API_URL ,
24- } ) ;
34+ proxy : proxyUrl ? {
35+ host : proxyUrl . hostname ,
36+ port : proxyUrl . port ? Number ( proxyUrl . port ) : 80
37+ } : false
38+ } ;
39+
40+ if ( SMARTUI_API_SKIP_CERTIFICATES ) {
41+ axiosConfig . httpsAgent = new https . Agent ( {
42+ rejectUnauthorized : false
43+ } ) ;
44+ }
45+
46+ this . axiosInstance = axios . create ( axiosConfig ) ;
47+
48+
2549 this . axiosInstance . interceptors . request . use ( ( config ) => {
2650 config . headers [ 'projectToken' ] = this . projectToken ;
2751 config . headers [ 'projectName' ] = this . projectName ;
0 commit comments