mirror of
https://github.com/Lissy93/web-check.git
synced 2025-08-09 05:04:31 +02:00
Working on traceroute component
This commit is contained in:
35
server/lambda/trace-route.js
Normal file
35
server/lambda/trace-route.js
Normal file
@ -0,0 +1,35 @@
|
||||
const traceroute = require('traceroute');
|
||||
const util = require('util');
|
||||
const url = require('url');
|
||||
|
||||
// Convert traceroute.trace method to return a Promise
|
||||
const traceroutePromise = util.promisify(traceroute.trace);
|
||||
|
||||
exports.handler = async function(event, context) {
|
||||
const urlString = event.queryStringParameters.url;
|
||||
|
||||
try {
|
||||
if (!urlString) {
|
||||
throw new Error('URL parameter is missing!');
|
||||
}
|
||||
|
||||
// Parse the URL and get the hostname
|
||||
const urlObject = url.parse(urlString);
|
||||
const host = urlObject.hostname;
|
||||
|
||||
if (!host) {
|
||||
throw new Error('Invalid URL provided');
|
||||
}
|
||||
|
||||
const result = await traceroutePromise(host);
|
||||
return {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify({ message: "Traceroute completed!", result }),
|
||||
};
|
||||
} catch (err) {
|
||||
return {
|
||||
statusCode: 500,
|
||||
body: JSON.stringify({ message: `Error: ${err.message}` }),
|
||||
};
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user