Skip to content

Commit

Permalink
Fix erreur proxyConfig et ajout proxy bypass-config (#46)
Browse files Browse the repository at this point in the history
* fix warning methode rmDir dépreciée, fix readProxy toujours en erreur YAML non valide, ajout Proxy bypass dans les browserArgs

* ajout configuration proxy pour appel Axios

Co-authored-by: Grégory BERTHELOT <[email protected]>
  • Loading branch information
Gregnarok and Grégory BERTHELOT authored Sep 25, 2022
1 parent 60ebaf0 commit 17338d1
Show file tree
Hide file tree
Showing 4 changed files with 2,862 additions and 308 deletions.
2 changes: 1 addition & 1 deletion cli-core/analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ async function createJsonReports(browser, pagesInformations, options, proxy, hea

//create directory for subresults
if (fs.existsSync(SUBRESULTS_DIRECTORY)){
fs.rmdirSync(SUBRESULTS_DIRECTORY, { recursive: true });
fs.rmSync(SUBRESULTS_DIRECTORY, { recursive: true });
}
fs.mkdirSync(SUBRESULTS_DIRECTORY);
//Asynchronous analysis with MAX_TAB open simultaneously to json
Expand Down
17 changes: 15 additions & 2 deletions cli-core/reportGlobal.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,22 @@ async function create_global_report(reports,options){
}
if (progressBar) progressBar.tick()
})
//Add info the the recap sheet

let proxy = null;
if (options.proxy?.server) {
const { protocol, hostname: host, port } = new URL(options.proxy.server);
const { user, password } = options.proxy;
const auth = user && password ? { username: user, password } : undefined;
proxy = {
protocol: protocol.slice(0,-1),
host,
port,
auth
};
}
//Add info the recap sheet
//Prepare data
const isMobile = (await axios.get('http://ip-api.com/json/?fields=mobile')).data.mobile //get connection type
const isMobile = (await axios.get('http://ip-api.com/json/?fields=mobile',{proxy})).data.mobile //get connection type
const date = new Date();
eco = (reports.length-err.length != 0)? Math.round(eco / (reports.length-err.length)) : "No data"; //Average EcoIndex
let grade = getEcoIndexGrade(eco)
Expand Down
7 changes: 5 additions & 2 deletions commands/analyse.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ async function analyse_core(options) {
let proxy = {};
if(options.proxy) {
proxy = readProxy(options.proxy);
browserArgs.push(`--proxy-server=${proxy.server}`);
if(proxy.bypass){
browserArgs.push(`--proxy-bypass-list=${proxy.bypass}`);
}
}

// Read headers http file
Expand Down Expand Up @@ -74,7 +78,7 @@ async function analyse_core(options) {
await browser.close()
}
//create report
let reportObj = await create_global_report(reports, options);
let reportObj = await create_global_report(reports, {...options, proxy});
if (reportFormat === 'html') {
await create_html_report(reportObj, options);
} else if (reportFormat === 'influxdb') {
Expand All @@ -94,7 +98,6 @@ function readProxy(proxyFile) {
if (!proxy.server || !proxy.user || !proxy.password) {
throw `proxy_config_file : Bad format "${PROXY_FILE}". Expected server, user and password.`
}
browserArgs.push(`--proxy-server=${proxy.server}`);
} catch (error) {
throw ` proxy_config_file : "${PROXY_FILE}" is not a valid YAML file.`
}
Expand Down
Loading

0 comments on commit 17338d1

Please sign in to comment.