Skip to content

Commit d36882e

Browse files
Merge pull request #120 from Nick-1234531/DOT-7102
added support for SMARTUI_API_PROXY
2 parents fec2414 + d5f291b commit d36882e

File tree

9 files changed

+61
-20
lines changed

9 files changed

+61
-20
lines changed

commands/storybook.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { default: axios } = require('axios')
1+
const { httpClient } = require('./utils/httpClient')
22
const fs = require('fs')
33
const { sendDoM } = require('./utils/dom')
44
const { validateStorybookUrl, validateStorybookDir } = require('./utils/validate')
@@ -27,7 +27,7 @@ async function storybook(serve, options) {
2727
storybookConfig.browsers = (!storybookConfig.browsers.length) ? 'all' : storybookConfig.browsers.map(x => x.toLowerCase()).toString();
2828

2929
// Get stories object from stories.json and add url corresponding to every story ID
30-
await axios.get(new URL('stories.json', url).href)
30+
await httpClient.get(new URL('stories.json', url).href)
3131
.then(async function (response) {
3232
let stories = {}
3333
for (const [storyId, storyInfo] of Object.entries(response.data.stories)) {
@@ -101,7 +101,7 @@ async function storybook(serve, options) {
101101
// Upload to S3
102102
const zipData = fs.readFileSync('storybook-static.zip');
103103
console.log('[smartui] Upload in progress...')
104-
await axios.put(url, zipData, {
104+
await httpClient.put(url, zipData, {
105105
headers: {
106106
'Content-Type': 'application/zip',
107107
'Content-Length': zipData.length
@@ -183,7 +183,7 @@ async function storybook(serve, options) {
183183
}
184184

185185
// Call static render API
186-
await axios.post(new URL(constants[options.env].STATIC_RENDER_PATH, constants[options.env].BASE_URL).href, payload)
186+
await httpClient.post(new URL(constants[options.env].STATIC_RENDER_PATH, constants[options.env].BASE_URL).href, payload)
187187
.then(async function (response) {
188188
if (response.data && response.data.error) {
189189
console.log('[smartui] Error: ', response.data.error.message);

commands/utils/dom.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const axios = require('axios');
1+
const { httpClient } = require('./httpClient');
22
const fs = require('fs');
33
const path = require('path')
44
const formData = require('form-data');
@@ -73,7 +73,7 @@ async function sendDoM(storybookUrl, stories, storybookConfig, options) {
7373
}
7474

7575
// Send DOM to render API
76-
await axios.post(constants[options.env].RENDER_API_URL, form, {
76+
await httpClient.post(constants[options.env].RENDER_API_URL, form, {
7777
headers: {
7878
...form.getHeaders()
7979
}
@@ -99,7 +99,7 @@ async function sendDoM(storybookUrl, stories, storybookConfig, options) {
9999
};
100100

101101
function getBase64(url) {
102-
return axios.get(url, {
102+
return httpClient.get(url, {
103103
responseType: "text",
104104
responseEncoding: "base64",
105105
})

commands/utils/httpClient.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const axios = require('axios');
2+
const https = require('https');
3+
4+
let proxyUrl = null;
5+
6+
// Handle proxy URL configuration
7+
try {
8+
const SMARTUI_API_PROXY = process.env.SMARTUI_API_PROXY;
9+
if (SMARTUI_API_PROXY) {
10+
const urlStr = SMARTUI_API_PROXY.startsWith('http') ?
11+
SMARTUI_API_PROXY : `http://${SMARTUI_API_PROXY}`;
12+
proxyUrl = new URL(urlStr);
13+
}
14+
} catch (error) {
15+
console.error('[smartui] Invalid proxy URL:', error.message);
16+
}
17+
18+
const axiosConfig = {
19+
proxy: proxyUrl ? {
20+
host: proxyUrl.hostname,
21+
port: proxyUrl.port ? Number(proxyUrl.port) : 80,
22+
...(proxyUrl.username && proxyUrl.password ? {
23+
auth: {
24+
username: proxyUrl.username,
25+
password: proxyUrl.password
26+
}
27+
} : {})
28+
} : false
29+
};
30+
31+
// Handle certificate verification skip
32+
if (process.env.SMARTUI_API_SKIP_CERTIFICATES) {
33+
axiosConfig.httpsAgent = new https.Agent({
34+
rejectUnauthorized: false
35+
});
36+
}
37+
38+
const httpClient = axios.create(axiosConfig);
39+
40+
module.exports = { httpClient };
41+

commands/utils/package.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const axios = require('axios');
21
var { constants } = require('./constants');
2+
const { httpClient } = require('./httpClient');
33

44
// Check for package updates
55
function checkUpdate(version, options) {
6-
return axios.get(new URL(constants[options.env].CHECK_UPDATE_PATH, constants[options.env].BASE_URL).href, {
6+
return httpClient.get(new URL(constants[options.env].CHECK_UPDATE_PATH, constants[options.env].BASE_URL).href, {
77
params: {
88
packageName: 'smartui-storybook',
99
packageVersion: version

commands/utils/polling.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const axios = require('axios');
1+
const { httpClient } = require('./httpClient');
22
const Table = require('cli-table3');
33
var { constants } = require('./constants');
44

@@ -10,7 +10,7 @@ var CURRENT_TIME = 0
1010
var FLAG = 0
1111

1212
async function shortPolling(buildId, retries = 0, options) {
13-
await axios.get(new URL('?buildId=' + buildId, constants[options.env].BUILD_STATUS_URL).href, {
13+
await httpClient.get(new URL('?buildId=' + buildId, constants[options.env].BUILD_STATUS_URL).href, {
1414
headers: {
1515
projectToken: process.env.PROJECT_TOKEN
1616
}})

commands/utils/static.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const fs = require('fs');
2-
const axios = require('axios');
2+
const { httpClient } = require('./httpClient');
33
const archiver = require('archiver');
44
var { constants } = require('./constants');
55
const { skipStory } = require('./story');
@@ -9,7 +9,7 @@ var INTERVAL = 2000
99
const MAX_INTERVAL = 512000
1010

1111
function getSignedUrl(options) {
12-
return axios.get(new URL(constants[options.env].GET_SIGNED_URL_PATH, constants[options.env].BASE_URL).href, {
12+
return httpClient.get(new URL(constants[options.env].GET_SIGNED_URL_PATH, constants[options.env].BASE_URL).href, {
1313
headers: {
1414
projectToken: process.env.PROJECT_TOKEN
1515
}});

commands/utils/validate.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const axios = require('axios');
1+
const { httpClient } = require('./httpClient');
22
var { constants } = require('./constants');
33
const fs = require('fs');
44
const { getLastCommit } = require('./git');
@@ -18,7 +18,7 @@ class ValidationError extends Error {
1818

1919
function validateProjectToken(options) {
2020
if (process.env.PROJECT_TOKEN) {
21-
return axios.get(constants[options.env].AUTH_URL, {
21+
return httpClient.get(constants[options.env].AUTH_URL, {
2222
headers: {
2323
projectToken: process.env.PROJECT_TOKEN
2424
}
@@ -51,7 +51,7 @@ function validateStorybookUrl(url) {
5151
console.log('[smartui] Error: ', error.message)
5252
process.exit(constants.ERROR_CATCHALL);
5353
}
54-
return axios.get(aboutUrl)
54+
return httpClient.get(aboutUrl)
5555
.then(function (response) {
5656
console.log('[smartui] Connection to storybook established');
5757
})
@@ -87,7 +87,7 @@ async function validateStorybookDir(dir) {
8787

8888
async function validateLatestBuild(options) {
8989
let commit = await getLastCommit();
90-
return axios.get(new URL(constants[options.env].SB_BUILD_VALIDATE_PATH, constants[options.env].BASE_URL).href, {
90+
return httpClient.get(new URL(constants[options.env].SB_BUILD_VALIDATE_PATH, constants[options.env].BASE_URL).href, {
9191
headers: {
9292
projectToken: process.env.PROJECT_TOKEN
9393
},

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lambdatest/smartui-storybook",
3-
"version": "1.1.29",
3+
"version": "1.1.30",
44
"description": "LambdaTest's command-line interface (CLI) aimed to help you run your SmartUI tests on LambdaTest platform",
55
"main": "index.js",
66
"repository": {

0 commit comments

Comments
 (0)