diff --git a/lib/check-status-code.js b/lib/check-status-code.js index 591b156..95b4833 100644 --- a/lib/check-status-code.js +++ b/lib/check-status-code.js @@ -41,7 +41,12 @@ function axiosRequest(urlToCheck, axiosOptions, redirect) { if (error.response && error.response.status) { httpStatus[2] = error.response.status; if (error.response.status >= 300 && error.response.status < 400) { - const redUrl = error.response.headers.location; + let redUrl = error.response.headers.location; + // if relative url, prepend the current protocol and hostname + if(redUrl.startsWith('/')){ + const url = new URL(urlToCheck); + redUrl = `${url.protocol}//${url.hostname}${redUrl}`; + } const checkType = await axiosRequest(redUrl, axiosOptions, true); httpStatus[3] = error.response.headers.location;