MCPcopy
hub / github.com/lissy93/web-check / traceRouteHandler

Function traceRouteHandler

api/trace-route.js:31–55  ·  view source on GitHub ↗
(url)

Source from the content-addressed store, hash-verified

29 err?.code === 'ENOENT' || /command not found|not installed/i.test(err?.message || '');
30
31const traceRouteHandler = async (url) => {
32 const start = Date.now();
33 const { hostname } = parseTarget(url);
34 let hops;
35 try {
36 hops = await runTraceroute(hostname);
37 } catch (err) {
38 if (isMissingBinary(err)) {
39 return {
40 skipped:
41 'Traceroute is not installed in this environment. ' +
42 'Install via your package manager, or run web-check via Docker.',
43 };
44 }
45 return { error: `Traceroute failed: ${err.message}` };
46 }
47 if (!hops.length) {
48 return { skipped: 'Traceroute returned no answered hops for this host' };
49 }
50 return {
51 message: 'Traceroute completed!',
52 result: hops.map(({ ip, time }) => ({ [ip]: [time] })),
53 timeTaken: Date.now() - start,
54 };
55};
56
57export const handler = middleware(traceRouteHandler);
58export default handler;

Callers

nothing calls this directly

Calls 3

parseTargetFunction · 0.90
runTracerouteFunction · 0.85
isMissingBinaryFunction · 0.85

Tested by

no test coverage detected