mirror of
https://github.com/Lissy93/web-check.git
synced 2025-01-25 07:38:37 +01:00
32 lines
629 B
JavaScript
32 lines
629 B
JavaScript
|
exports.handler = async (event) => {
|
||
|
const { url } = event.queryStringParameters;
|
||
|
const redirects = [];
|
||
|
|
||
|
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) {
|
||
|
return {
|
||
|
statusCode: 500,
|
||
|
body: `Error: ${error.message}`,
|
||
|
};
|
||
|
}
|
||
|
};
|