Вы можете установить maxRedirects
на 0
, тогда перенаправление будет считаться ошибкой, и вы сможете получить заголовок Location
:
const geturl = async link => {
try {
return await axios({
method: "get",
url: link,
maxRedirects: 0
});
} catch (e) {
if (Math.trunc(e.response.status / 100) === 3) {
console.log(e.response.headers.location);
return geturl(e.response.headers.location);
} else {
throw e;
}
}
};
geturl("http://google.com").then(x => x.status).then(console.log);