import axios from 'axios'; import cheerio from 'cheerio'; const fetchTarget = async (target: string) => { return await axios.get(target, { maxRedirects: 0, validateStatus: (status) => { return status >= 200 && status < 400; }, }); }; export const getLocationOfTarget = async (target: string) => { try { const response = await fetchTarget(target); if (response.headers.location) { return response.headers.location as string; } // for reurl.cc if (target.includes('reurl.cc')) { const $ = cheerio.load(response.data); return $('#url').attr('value'); } } catch (err) { console.log(err); } return undefined; };