mirror of
https://github.com/Lissy93/web-check.git
synced 2024-11-29 19:54:49 +01:00
28 lines
573 B
JavaScript
28 lines
573 B
JavaScript
const handler = async (url) => {
|
|
const redirects = [url];
|
|
const got = await import('got');
|
|
|
|
try {
|
|
await got.default(url, {
|
|
followRedirect: true,
|
|
maxRedirects: 12,
|
|
hooks: {
|
|
beforeRedirect: [
|
|
(options, response) => {
|
|
redirects.push(response.headers.location);
|
|
},
|
|
],
|
|
},
|
|
});
|
|
|
|
return {
|
|
redirects: redirects,
|
|
};
|
|
} catch (error) {
|
|
throw new Error(`Error: ${error.message}`);
|
|
}
|
|
};
|
|
|
|
const middleware = require('./_common/middleware');
|
|
exports.handler = middleware(handler);
|