Skip to content

Commit 9b4016b

Browse files
add smartui api proxy and smartui api skip certificates
1 parent 176583d commit 9b4016b

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

src/lib/env.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export default (): Env => {
1818
BASELINE_BRANCH,
1919
CURRENT_BRANCH,
2020
PROJECT_NAME,
21+
SMARTUI_API_PROXY,
22+
SMARTUI_API_SKIP_CERTIFICATES
2123
} = process.env
2224

2325
return {
@@ -36,6 +38,8 @@ export default (): Env => {
3638
CURRENT_BRANCH,
3739
LT_SDK_DEBUG: LT_SDK_DEBUG === 'true',
3840
SMARTUI_DO_NOT_USE_CAPTURED_COOKIES: SMARTUI_DO_NOT_USE_CAPTURED_COOKIES === 'true',
39-
PROJECT_NAME
41+
PROJECT_NAME,
42+
SMARTUI_API_PROXY,
43+
SMARTUI_API_SKIP_CERTIFICATES: SMARTUI_API_SKIP_CERTIFICATES === 'true'
4044
}
4145
}

src/lib/httpClient.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Env, Snapshot, ProcessedSnapshot, Git, Build, Context } from '../types.
55
import constants from './constants.js';
66
import type { Logger } from 'winston'
77
import pkgJSON from './../../package.json'
8+
import https from 'https';
89

910
export default class httpClient {
1011
axiosInstance: AxiosInstance;
@@ -13,15 +14,36 @@ 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+
proxyUrl = SMARTUI_API_PROXY ? new URL(SMARTUI_API_PROXY) : null;
26+
} catch (error) {
27+
console.error('Invalid proxy URL:', error);
28+
}
29+
const axiosConfig: any = {
2330
baseURL: SMARTUI_CLIENT_API_URL,
24-
});
31+
proxy: proxyUrl ? {
32+
host: proxyUrl.hostname,
33+
port: proxyUrl.port ? Number(proxyUrl.port) : 80
34+
} : false
35+
};
36+
37+
if (SMARTUI_API_SKIP_CERTIFICATES) {
38+
axiosConfig.httpsAgent = new https.Agent({
39+
rejectUnauthorized: false
40+
});
41+
}
42+
43+
console.log('Axios Config:', JSON.stringify(axiosConfig, null, 2));
44+
this.axiosInstance = axios.create(axiosConfig);
45+
46+
2547
this.axiosInstance.interceptors.request.use((config) => {
2648
config.headers['projectToken'] = this.projectToken;
2749
config.headers['projectName'] = this.projectName;

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ export interface Env {
7171
BASELINE_BRANCH: string | undefined;
7272
CURRENT_BRANCH: string | undefined;
7373
PROJECT_NAME: string | undefined;
74+
SMARTUI_API_PROXY: string | undefined;
75+
SMARTUI_API_SKIP_CERTIFICATES: boolean;
7476
}
7577

7678
export interface Snapshot {

0 commit comments

Comments
 (0)