2023-06-29 01:27:09 +02:00
|
|
|
exports.handler = async (event) => {
|
2023-07-28 22:46:20 +02:00
|
|
|
const url = (event.queryStringParameters || event.query).url;
|
2023-07-22 01:05:09 +02:00
|
|
|
const redirects = [url];
|
2023-06-29 01:27:09 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
const got = await import('got');
|
|
|
|
await got.default(url, {
|
|
|
|
followRedirect: true,
|
|
|
|
maxRedirects: 12,
|
|
|
|
hooks: {
|
|
|
|
beforeRedirect: [
|
|
|
|
(options, response) => {
|
|
|
|
redirects.push(response.headers.location);
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
statusCode: 200,
|
|
|
|
body: JSON.stringify({
|
|
|
|
redirects: redirects,
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
} catch (error) {
|
2023-07-10 00:23:50 +02:00
|
|
|
return errorResponse(`Error: ${error.message}`);
|
2023-06-29 01:27:09 +02:00
|
|
|
}
|
|
|
|
};
|
2023-07-10 00:23:50 +02:00
|
|
|
|
|
|
|
const errorResponse = (message, statusCode = 444) => {
|
|
|
|
return {
|
|
|
|
statusCode: statusCode,
|
|
|
|
body: JSON.stringify({ error: message }),
|
|
|
|
};
|
|
|
|
};
|