diff --git a/api-docs/doh-api.json b/api-docs/doh-api.json new file mode 100644 index 0000000..2ca5bb0 --- /dev/null +++ b/api-docs/doh-api.json @@ -0,0 +1,263 @@ +{ + "info": { + "_postman_id": "a7f3c891-2b4e-5d6c-8e9f-0a1b2c3d4e5f", + "name": "doh-api", + "description": "Cloudflare Worker:DoH 代理、DNS 解析 API、IP 地理信息。\n\n仅使用集合变量(无独立环境),默认指向生产:`{{baseUrl}}`。\n\n- `dohPath`:DoH 路径段,默认与 Worker 未配置 `PATH`/`TOKEN` 时一致(`dns-query`)。若部署时通过环境变量修改了路径,请同步改此变量。\n- `token`:当 Worker 配置了 `TOKEN` 时,`/ip-info` 必填;未配置可留空。", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "variable": [ + { + "key": "baseUrl", + "value": "https://cf-dns.smyhub.com" + }, + { + "key": "dohPath", + "value": "dns-query" + }, + { + "key": "domain", + "value": "www.google.com" + }, + { + "key": "url", + "value": "https://example.com/path" + }, + { + "key": "ip", + "value": "1.1.1.1" + }, + { + "key": "token", + "value": "" + }, + { + "key": "dohServerUrl", + "value": "https://cf-dns.smyhub.com/dns-query" + }, + { + "key": "dnsQueryType", + "value": "all" + }, + { + "key": "dnsWireBase64url", + "value": "" + } + ], + "item": [ + { + "name": "DoH", + "item": [ + { + "name": "DNS JSON (GET)", + "request": { + "method": "GET", + "header": [ + { + "key": "Accept", + "value": "application/dns-json" + } + ], + "url": { + "raw": "{{baseUrl}}/{{dohPath}}?name={{domain}}&type=A", + "query": [ + { + "key": "name", + "value": "{{domain}}" + }, + { + "key": "type", + "value": "A", + "description": "DNS 记录类型,如 A、AAAA、NS、TXT 等" + } + ] + }, + "description": "RFC 8484 JSON DoH:`name` 与 `type` 查询。无查询字符串且 GET 时返回 400。" + }, + "response": [] + }, + { + "name": "DNS wire (GET, dns parameter)", + "request": { + "method": "GET", + "header": [ + { + "key": "Accept", + "value": "application/dns-message" + } + ], + "url": { + "raw": "{{baseUrl}}/{{dohPath}}?dns={{dnsWireBase64url}}", + "query": [ + { + "key": "dns", + "value": "{{dnsWireBase64url}}", + "description": "DNS 报文 Base64url 编码(需自行生成)" + } + ] + }, + "description": "GET 且非 `name` 参数分支:使用 `dns` 查询参数传递 wire format。" + }, + "response": [] + }, + { + "name": "DNS wire (POST)", + "request": { + "method": "POST", + "header": [ + { + "key": "Accept", + "value": "application/dns-message" + }, + { + "key": "Content-Type", + "value": "application/dns-message" + } + ], + "body": { + "mode": "raw", + "raw": "", + "options": { + "raw": { + "language": "text" + } + } + }, + "url": "{{baseUrl}}/{{dohPath}}", + "description": "POST 二进制 DNS 报文,转发至上游 DoH。请在 Body 中填入原始 DNS wire bytes(非 JSON)。" + }, + "response": [] + }, + { + "name": "OPTIONS (CORS preflight)", + "request": { + "method": "OPTIONS", + "header": [], + "url": "{{baseUrl}}/{{dohPath}}", + "description": "预检请求,返回 CORS 头。" + }, + "response": [] + } + ] + }, + { + "name": "REST", + "item": [ + { + "name": "解析域名 IP (/api/dns?domain)", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{baseUrl}}/api/dns?domain={{domain}}", + "query": [ + { + "key": "domain", + "value": "{{domain}}" + }, + { + "key": "url", + "value": "{{url}}", + "disabled": true, + "description": "与 domain 二选一,也可使用 url 参数" + } + ] + }, + "description": "返回域名的 IPv4、IPv6、CNAME 等聚合结果。参数 `url` 与 `domain` 任选其一。" + }, + "response": [] + }, + { + "name": "解析 URL 对应 IP (/api/dns?url)", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{baseUrl}}/api/dns?url={{url}}", + "query": [ + { + "key": "url", + "value": "{{url}}" + } + ] + }, + "description": "从完整 URL 提取 hostname 再查询 DNS。" + }, + "response": [] + }, + { + "name": "通过 doh 参数代理查询 (GET)", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{baseUrl}}/?doh={{dohServerUrl}}&domain={{domain}}&type={{dnsQueryType}}", + "query": [ + { + "key": "doh", + "value": "{{dohServerUrl}}", + "description": "目标 DoH 完整 URL;若包含当前站点 host,则走本地合并逻辑" + }, + { + "key": "domain", + "value": "{{domain}}", + "description": "也可用 name 参数" + }, + { + "key": "name", + "value": "{{domain}}", + "disabled": true + }, + { + "key": "type", + "value": "{{dnsQueryType}}", + "description": "默认 all:A+AAAA+NS 合并;其它值为单次 queryDns" + } + ] + }, + "description": "路径需避开 `/dns-query`、`/ip-info`、`/api/dns` 时,通常使用 `/?doh=...`。`type=all` 时返回合并 JSON。" + }, + "response": [] + } + ] + }, + { + "name": "IP", + "item": [ + { + "name": "IP 地理信息 (/ip-info)", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{baseUrl}}/ip-info?ip={{ip}}&token={{token}}", + "query": [ + { + "key": "ip", + "value": "{{ip}}", + "description": "可选;省略时使用 CF-Connecting-IP(浏览器直连场景)" + }, + { + "key": "token", + "value": "{{token}}", + "description": "Worker 配置 TOKEN 时必填" + } + ] + }, + "description": "代理 ip-api.com,中文 lang。未传 ip 时在 Worker 边缘可自动取客户端 IP。" + }, + "response": [] + }, + { + "name": "OPTIONS /ip-info (CORS)", + "request": { + "method": "OPTIONS", + "header": [], + "url": "{{baseUrl}}/ip-info", + "description": "预检。" + }, + "response": [] + } + ] + } + ] +} diff --git a/wrangler.toml b/wrangler.toml index f8cec8f..de03df4 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -1,3 +1,3 @@ -name = "cf-doh-dns" +name = "doh-api" main = "worker.js" compatibility_date = "2024-09-23"