This repository has been archived on 2021-05-27. You can view files and clone it, but cannot push or open issues or pull requests.
Files
ReRedirector/src/app.service.ts
2020-04-04 05:13:26 +08:00

33 lines
768 B
TypeScript

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;
};