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

Function robotsHandler

api/robots-txt.js:17–30  ·  view source on GitHub ↗
(url)

Source from the content-addressed store, hash-verified

15};
16
17const robotsHandler = async (url) => {
18 const { protocol, hostname } = parseTarget(url);
19 const host = hostname.includes(':') ? `[${hostname}]` : hostname;
20 try {
21 const res = await httpGet(`${protocol}//${host}/robots.txt`);
22 const parsed = parseRobotsTxt(res.data || '');
23 return parsed.robots.length ? parsed : { skipped: 'No robots.txt rules found for this host' };
24 } catch (error) {
25 if (error.response?.status === 404) {
26 return { skipped: 'No robots.txt file present on this host' };
27 }
28 return upstreamError(error, 'robots.txt fetch');
29 }
30};
31
32export const handler = middleware(robotsHandler);
33export default handler;

Callers

nothing calls this directly

Calls 4

parseTargetFunction · 0.90
httpGetFunction · 0.90
upstreamErrorFunction · 0.90
parseRobotsTxtFunction · 0.70

Tested by

no test coverage detected