(url)
| 15 | }; |
| 16 | |
| 17 | const 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 | |
| 32 | export const handler = middleware(robotsHandler); |
| 33 | export default handler; |
nothing calls this directly
no test coverage detected