diff --git a/app/scripts/network-helper.js b/app/scripts/network-helper.js index 2f72867..6d17630 100644 --- a/app/scripts/network-helper.js +++ b/app/scripts/network-helper.js @@ -5,9 +5,6 @@ const {readFileSync, writeFileSync, existsSync} = require("fs"); // Public modules from npm const axios = require("axios").default; -const ky = require("ky-universal").create({ - throwHttpErrors: false, -}); const cheerio = require("cheerio"); const axiosCookieJarSupport = require("axios-cookiejar-support").default; const tough = require("tough-cookie"); @@ -249,23 +246,23 @@ module.exports.isStringAValidURL = function (url) { * @protected * Check if a particular URL is valid and reachable on the web. * @param {String} url URL to check - * @param {Boolean} checkRedirect If true, the function will consider redirects a violation and return false + * @param {Boolean} [checkRedirect] + * If true, the function will consider redirects a violation and return false. + * Default: false * @returns {Promise} true if the URL exists, false otherwise */ -module.exports.urlExists = async function (url, checkRedirect) { - if (!exports.isStringAValidURL(url)) { - return false; - } +module.exports.urlExists = async function (url, checkRedirect = false) { + // Local variables + let valid = false; - const response = await ky.head(url); - let valid = response !== undefined && !/4\d\d/.test(response.status); + if (exports.isStringAValidURL(url)) { + const response = await axios.head(url); + valid = response && !/4\d\d/.test(response.status); - if (!valid) return false; - - if (checkRedirect) { - const redirectUrl = await exports.getUrlRedirect(url); - if (redirectUrl === url) valid = true; - else valid = false; + if (valid && checkRedirect) { + const redirectUrl = await exports.getUrlRedirect(url); + valid = redirectUrl === url; + } } return valid; @@ -278,7 +275,7 @@ module.exports.urlExists = async function (url, checkRedirect) { * @returns {Promise} Redirect URL or the passed URL */ module.exports.getUrlRedirect = async function (url) { - const response = await ky.head(url); - return response.url; + const response = await axios.head(url); + return response.config.url; }; //#endregion Utility methods \ No newline at end of file