@@ -5,6 +5,7 @@ import { Env, Snapshot, ProcessedSnapshot, Git, Build, Context } from '../types.
5
5
import constants from './constants.js' ;
6
6
import type { Logger } from 'winston'
7
7
import pkgJSON from './../../package.json'
8
+ import https from 'https' ;
8
9
9
10
export default class httpClient {
10
11
axiosInstance : AxiosInstance ;
@@ -13,15 +14,38 @@ export default class httpClient {
13
14
username : string ;
14
15
accessKey : string ;
15
16
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 ) {
17
18
this . projectToken = PROJECT_TOKEN || '' ;
18
19
this . projectName = PROJECT_NAME || '' ;
19
20
this . username = LT_USERNAME || '' ;
20
21
this . accessKey = LT_ACCESS_KEY || '' ;
21
22
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 = {
23
33
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
+
25
49
this . axiosInstance . interceptors . request . use ( ( config ) => {
26
50
config . headers [ 'projectToken' ] = this . projectToken ;
27
51
config . headers [ 'projectName' ] = this . projectName ;
@@ -84,14 +108,15 @@ export default class httpClient {
84
108
}
85
109
}
86
110
87
- createBuild ( git : Git , config : any , log : Logger , buildName : string ) {
111
+ createBuild ( git : Git , config : any , log : Logger , buildName : string , isStartExec : boolean ) {
88
112
return this . request ( {
89
113
url : '/build' ,
90
114
method : 'POST' ,
91
115
data : {
92
116
git,
93
117
config,
94
- buildName
118
+ buildName,
119
+ isStartExec
95
120
}
96
121
} , log )
97
122
}
@@ -102,7 +127,18 @@ export default class httpClient {
102
127
method : 'GET' ,
103
128
params : { buildId, baseline }
104
129
} , log ) ;
105
- }
130
+ }
131
+
132
+ ping ( buildId : string , log : Logger ) {
133
+ return this . request ( {
134
+ url : '/build/ping' ,
135
+ method : 'POST' ,
136
+ data : {
137
+ buildId : buildId
138
+ }
139
+ } , log ) ;
140
+ }
141
+
106
142
107
143
finalizeBuild ( buildId : string , totalSnapshots : number , log : Logger ) {
108
144
let params : Record < string , string | number > = { buildId} ;
0 commit comments