diff --git a/lib.js b/lib.js index dde39a1..318eb41 100644 --- a/lib.js +++ b/lib.js @@ -2,4 +2,22 @@ const followRedirect = require("./follow-redirect-url"); +exports.expandUrl = async function(url) { + let resolvedUrlList; + + resolvedUrlList = await followRedirect.startFollowing(url, { + ignoreSslErrors: true, + }); + + const lastUrlHop = resolvedUrlList[resolvedUrlList.length - 1]; + + if(lastUrlHop.error) { + return [false, lastUrlHop] + } + + const resolvedUrl = resolvedUrlList[resolvedUrlList.length - 1].url; + + return [true, resolvedUrl]; +} + exports.startFollowing = followRedirect.startFollowing;