あいつの日誌β

働きながら旅しています。

How to get the real URL behind a shortened URL using cURL and axios

こういうのを Node.js でやりたい時は

$ curl -sLI http://shortened_url | grep -i Location

axios の get に以下のようなオプションを渡してあげるとよい

const axios = require('axios')

async function main () {
  const res = await axios.get('https://t.co/q0wn9eZvvY', {
    maxRedirects: 0,
    validateStatus: null
  })  
  console.log(res.headers.location)
}

main()