Skip to content

Commit

Permalink
✨ Adds backend support for status check redirects (Re: #494)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lissy93 committed Mar 13, 2022
1 parent eae4349 commit 4779434
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions services/status-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,23 @@ const makeErrorMessage2 = (data) => '❌ Service Error - '
+ `${data.status} - ${data.statusText}`;

/* Kicks of a HTTP request, then formats and renders results */
const makeRequest = (url, headers, insecure, acceptCodes, render) => {
const makeRequest = (url, options, render) => {
console.log(options);
const {
headers, enableInsecure, acceptCodes, maxRedirects,
} = options;
const validCodes = acceptCodes && acceptCodes !== 'null' ? acceptCodes : null;
const startTime = new Date();
const requestMaker = axios.create({
httpsAgent: new https.Agent({
rejectUnauthorized: !insecure,
rejectUnauthorized: !enableInsecure,
}),
});
requestMaker.get(url, { headers })
requestMaker.request({
url,
headers,
maxRedirects,
})
.then((response) => {
const statusCode = response.status;
const { statusText } = response;
Expand Down Expand Up @@ -100,9 +108,13 @@ module.exports = (paramStr, render) => {
const params = new URLSearchParams(paramStr);
const url = decodeURIComponent(params.get('url'));
const acceptCodes = decodeURIComponent(params.get('acceptCodes'));
const maxRedirects = decodeURIComponent(params.get('maxRedirects')) || 0;
const headers = decodeHeaders(params.get('headers'));
const enableInsecure = !!params.get('enableInsecure');
if (!url || url === 'undefined') immediateError(render);
makeRequest(url, headers, enableInsecure, acceptCodes, render);
const options = {
headers, enableInsecure, acceptCodes, maxRedirects,
};
makeRequest(url, options, render);
}
};

0 comments on commit 4779434

Please sign in to comment.