mirror of
https://github.com/Lissy93/web-check.git
synced 2024-11-26 18:23:21 +01:00
36 lines
749 B
JavaScript
36 lines
749 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 errorResponse(`Error: ${error.message}`);
|
|
}
|
|
};
|
|
|
|
const errorResponse = (message, statusCode = 444) => {
|
|
return {
|
|
statusCode: statusCode,
|
|
body: JSON.stringify({ error: message }),
|
|
};
|
|
};
|