(url)
| 3 | import { parseTarget } from './_common/parse-target.js'; |
| 4 | |
| 5 | const txtRecordHandler = async (url) => { |
| 6 | const { hostname } = parseTarget(url); |
| 7 | const txtRecords = await dns.resolveTxt(hostname); |
| 8 | // Join chunks (DNS splits long records at 255 bytes), then key=value |
| 9 | const result = {}; |
| 10 | for (const chunks of txtRecords) { |
| 11 | const full = chunks.join(''); |
| 12 | const eq = full.indexOf('='); |
| 13 | let key = eq > 0 ? full.slice(0, eq) : full; |
| 14 | const val = eq > 0 ? full.slice(eq + 1) : ''; |
| 15 | while (key in result) key += '_'; |
| 16 | result[key] = val; |
| 17 | } |
| 18 | return result; |
| 19 | }; |
| 20 | |
| 21 | export const handler = middleware(txtRecordHandler); |
| 22 | export default handler; |
nothing calls this directly
no test coverage detected