2

Accessing https://link.medium.com/C1hxgiphAcb on browser is redirecting to https://medium.com/javascript-in-plain-english/add-size-limit-to-github-actions-551c8fe9e7d7

From the backend, I am trying to figure out the final URL, given the shortened URL.

I am using Axios package at the backend (nodeJS).

var mediumRequest = await Axios.get('https://link.medium.com/C1hxgiphAcb') 
console.log(mediumRequest.request.res.responseUrl) 
>> 'https://rsci.app.link/C1hxgiphAcb?_p=c21634dc9a016ceeeb1d90f4e8' 

But, that is not the actual Final URL.

Am I missing something?

Satya Kalluri
  • 5,148
  • 4
  • 28
  • 37

1 Answers1

2

This did the job, adding a user-agent to the headers that represent a browser.

url = 'https://link.medium.com/C1hxgiphAcb';
headers = { 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36' };
var x = await Axios.get(url, { headers: headers  } )
console.log(x.request.res.responseUrl)

Output = https://medium.com/javascript-in-plain-english/add-size-limit-to-github-actions-551c8fe9e7d7

Satya Kalluri
  • 5,148
  • 4
  • 28
  • 37