2023-08-09 23:33:36 +02:00
|
|
|
const handler = async (url) => {
|
2023-07-22 01:05:09 +02:00
|
|
|
const redirects = [url];
|
2023-08-09 23:33:36 +02:00
|
|
|
const got = await import('got');
|
2023-06-29 01:27:09 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
await got.default(url, {
|
|
|
|
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
|
|
|
|
2023-08-09 23:33:36 +02:00
|
|
|
const middleware = require('./_common/middleware');
|
|
|
|
exports.handler = middleware(handler);
|