2024-05-06 22:51:32 +02:00
|
|
|
import got from 'got';
|
|
|
|
import middleware from './_common/middleware.js';
|
2023-06-29 01:27:09 +02:00
|
|
|
|
2024-05-06 22:51:32 +02:00
|
|
|
const redirectsHandler = async (url) => {
|
|
|
|
const redirects = [url];
|
2023-06-29 01:27:09 +02:00
|
|
|
try {
|
2024-05-06 22:51:32 +02:00
|
|
|
await got(url, {
|
2023-06-29 01:27:09 +02:00
|
|
|
followRedirect: true,
|
|
|
|
maxRedirects: 12,
|
|
|
|
hooks: {
|
|
|
|
beforeRedirect: [
|
|
|
|
(options, response) => {
|
|
|
|
redirects.push(response.headers.location);
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
2023-08-09 23:33:36 +02:00
|
|
|
redirects: redirects,
|
2023-06-29 01:27:09 +02:00
|
|
|
};
|
|
|
|
} catch (error) {
|
2023-08-09 23:33:36 +02:00
|
|
|
throw new Error(`Error: ${error.message}`);
|
2023-06-29 01:27:09 +02:00
|
|
|
}
|
|
|
|
};
|
2023-07-10 00:23:50 +02:00
|
|
|
|
2024-05-06 22:51:32 +02:00
|
|
|
export const handler = middleware(redirectsHandler);
|
|
|
|
export default handler;
|