@aiti-ai/ddns-mocks 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aliyun.d.ts +36 -0
- package/dist/aliyun.js +103 -0
- package/dist/assets/mock-ca.key +28 -0
- package/dist/assets/mock-ca.pem +19 -0
- package/dist/assets/mock-server.key +28 -0
- package/dist/assets/mock-server.pem +21 -0
- package/dist/cloudflare.d.ts +38 -0
- package/dist/cloudflare.js +105 -0
- package/dist/custom.d.ts +24 -0
- package/dist/custom.js +22 -0
- package/dist/dnspod.d.ts +33 -0
- package/dist/dnspod.js +104 -0
- package/dist/duckdns.d.ts +24 -0
- package/dist/duckdns.js +41 -0
- package/dist/dyndns.d.ts +26 -0
- package/dist/dyndns.js +30 -0
- package/dist/freedns.d.ts +23 -0
- package/dist/freedns.js +28 -0
- package/dist/index.d.ts +74 -0
- package/dist/index.js +83 -0
- package/dist/loose.d.ts +58 -0
- package/dist/loose.js +1017 -0
- package/dist/rest.d.ts +41 -0
- package/dist/rest.js +279 -0
- package/dist/route53.d.ts +32 -0
- package/dist/route53.js +64 -0
- package/dist/tls.d.ts +42 -0
- package/dist/tls.js +140 -0
- package/package.json +26 -4
- package/README.md +0 -3
package/dist/loose.js
ADDED
|
@@ -0,0 +1,1017 @@
|
|
|
1
|
+
/** Loose zone REST mock — one shared mock for the hand-written providers
|
|
2
|
+
* whose CRUD follows the common zone-REST pattern (GET list, POST create,
|
|
3
|
+
* PUT update, DELETE by id) with varying paths/auth. It answers ANY path:
|
|
4
|
+
*
|
|
5
|
+
* GET → returns stored records (superset apiShape — every fields
|
|
6
|
+
* mapping in rest-specs can read name/content/data/…)
|
|
7
|
+
* POST → creates a record (parses name/value/type from any common
|
|
8
|
+
* body field via stdRec: name/host/domain, data/content/value)
|
|
9
|
+
* PUT → updates by trailing id segment
|
|
10
|
+
* DELETE → removes by trailing id segment
|
|
11
|
+
*
|
|
12
|
+
* Auth is checked per kind: bearer / basic / none / token-in-body.
|
|
13
|
+
* This is what makes every hand-written provider verifiable through
|
|
14
|
+
* verify-all.mjs (ours + lexicon over HTTPS_PROXY).
|
|
15
|
+
*/
|
|
16
|
+
import { createServer } from "node:http";
|
|
17
|
+
import { randomUUID } from "node:crypto";
|
|
18
|
+
const defaultFetchLike = null;
|
|
19
|
+
export async function startLooseZoneMock(opts = {}) {
|
|
20
|
+
const auth = opts.auth ?? "bearer";
|
|
21
|
+
const cred = opts.cred ?? "test-token";
|
|
22
|
+
const state = {
|
|
23
|
+
records: (opts.records ?? []).map((r) => ({ id: randomUUID(), ...r })),
|
|
24
|
+
requests: [],
|
|
25
|
+
};
|
|
26
|
+
const authOk = (req) => {
|
|
27
|
+
if (opts.header) {
|
|
28
|
+
const h = req.headers[opts.header.key.toLowerCase()];
|
|
29
|
+
if (h !== opts.header.value)
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
if (auth === "none")
|
|
33
|
+
return true;
|
|
34
|
+
if (auth === "basic")
|
|
35
|
+
return req.headers.authorization === `Basic ${Buffer.from(cred).toString("base64")}`;
|
|
36
|
+
return req.headers.authorization === `Bearer ${cred}`;
|
|
37
|
+
};
|
|
38
|
+
const apiShape = (r) => {
|
|
39
|
+
const [host, ...rest] = r.name.split(".");
|
|
40
|
+
return {
|
|
41
|
+
id: r.id, type: r.type, name: r.name, content: r.value, data: r.value,
|
|
42
|
+
value: r.value, target: r.value, answer: r.value, ttl: r.ttl ?? 300,
|
|
43
|
+
host: r.name.includes(".") ? host : "", domain: rest.join("."),
|
|
44
|
+
rrset_name: host, rrset_type: r.type, rrset_values: [r.value],
|
|
45
|
+
record_details: { id: r.id, record_type: r.type, name: r.name, data: r.value, ttl: r.ttl ?? 300 },
|
|
46
|
+
answers: [{ answer: [r.value] }], records: [r.value],
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
const stdRec = (body) => {
|
|
50
|
+
let parsed = body;
|
|
51
|
+
if (typeof body === "string") {
|
|
52
|
+
try {
|
|
53
|
+
parsed = JSON.parse(body);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
parsed = Object.fromEntries(new URLSearchParams(body));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const b = (Array.isArray(parsed) ? parsed[0] : parsed);
|
|
60
|
+
const isObj = (x) => typeof x === "object" && x !== null && !Array.isArray(x);
|
|
61
|
+
const additions = b.additions?.[0];
|
|
62
|
+
// Only treat record/dns_record/data/additions as a NESTED record object when
|
|
63
|
+
// it is actually an object — some providers (nfsn, gcp rrdatas) use `data`/
|
|
64
|
+
// `value` as a plain scalar string, which must NOT be unwrapped.
|
|
65
|
+
const nested = isObj(b.record) ? b.record : isObj(b.dns_record) ? b.dns_record : isObj(b.data) ? b.data : isObj(additions) ? additions : undefined;
|
|
66
|
+
const src = nested ?? b;
|
|
67
|
+
return {
|
|
68
|
+
type: String(src.type ?? src.record_type ?? src.rrtype ?? src.rtype ?? src.rdtype ?? src.Type ?? src.RecordType ?? ""),
|
|
69
|
+
name: String(src.name ?? src.host ?? src.hostname ?? src.domain ?? src.fqdn ?? src.Name ?? src.SubDomain ?? ""),
|
|
70
|
+
value: String(src.content ?? src.data ?? src.value ?? src.destination ?? src.target ?? src.answer ?? src.rdata ?? src.Value ?? src.ipv4addr ?? (src.answers?.[0]?.answer?.[0]) ?? ""),
|
|
71
|
+
ttl: src.ttl !== undefined ? Number(src.ttl) : src.TTL !== undefined ? Number(src.TTL) : undefined,
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
// Per-provider response-shape adaptation (the loose mock serves records,
|
|
75
|
+
// but each hand-written provider expects its own envelope/fields).
|
|
76
|
+
const formatFor = (p, method, urlPath, out) => {
|
|
77
|
+
const isCreate = method === "POST" || (method === "PUT" && !urlPath.split("/").filter(Boolean).length);
|
|
78
|
+
const recs = out.records ?? [];
|
|
79
|
+
const short = (r) => {
|
|
80
|
+
const rr = r;
|
|
81
|
+
const host = (rr.name ?? "").split(".")[0];
|
|
82
|
+
return { ...rr, record: rr.name, host, record_id: rr.id, value: rr.value, data: rr.value, rrhost: host };
|
|
83
|
+
};
|
|
84
|
+
switch (p) {
|
|
85
|
+
case "dreamhost":
|
|
86
|
+
return [200, { result: "success", data: method === "GET" ? recs.map(short) : undefined }];
|
|
87
|
+
case "namesilo":
|
|
88
|
+
return [200, { reply: { code: 300, detail: "success", resource_records: method === "GET" ? recs.map(short) : undefined } }];
|
|
89
|
+
case "netcup":
|
|
90
|
+
return [200, { status: "success", responsedata: method === "GET" ? { dnsrecords: recs ?? [] } : { dnsrecords: [{ id: "r1" }] } }];
|
|
91
|
+
case "dondominio":
|
|
92
|
+
return [200, { success: true }];
|
|
93
|
+
case "dnsmadeeasy":
|
|
94
|
+
return [200, { id: "z1", data: recs ?? [] }];
|
|
95
|
+
case "constellix":
|
|
96
|
+
// domain lookup first (GET /domains/), then records list
|
|
97
|
+
if (urlPath === "/domains/" || urlPath === "/domains")
|
|
98
|
+
return [200, { data: [{ id: "c1", name: "example.com" }] }];
|
|
99
|
+
return [200, { data: recs.map((r) => ({ id: r.id, name: r.name, type: r.type, ttl: r.ttl ?? 300, roundRobin: [{ disableFlag: false, value: r.value }] })) }];
|
|
100
|
+
case "ultradns":
|
|
101
|
+
return [200, { zones: [{ id: "z1", name: "example.com" }] }];
|
|
102
|
+
case "aurora":
|
|
103
|
+
if (urlPath === "/zones")
|
|
104
|
+
return [200, [{ id: "z1", name: "example.com" }]];
|
|
105
|
+
return [200, recs ?? []];
|
|
106
|
+
case "softlayer":
|
|
107
|
+
if (urlPath.includes("getResourceRecords"))
|
|
108
|
+
return [200, recs ?? []];
|
|
109
|
+
return [200, { data: recs ?? [] }];
|
|
110
|
+
case "transip":
|
|
111
|
+
return [200, { dnsEntries: recs.map((r) => { const rr = r; return { ...rr, id: `${rr.name ?? ""}/${rr.type ?? ""}` }; }) }];
|
|
112
|
+
case "hostingde":
|
|
113
|
+
case "httpnet":
|
|
114
|
+
// recordsFind/api returns {status, data:{records}}; always expose records
|
|
115
|
+
return [200, { status: "success", data: { records: recs ?? [] } }];
|
|
116
|
+
case "valuedomain":
|
|
117
|
+
// GET /domains/{z}/dns → {results:[...]}
|
|
118
|
+
return [200, { results: recs ?? [] }];
|
|
119
|
+
case "cloudxns":
|
|
120
|
+
if (urlPath === "/domain")
|
|
121
|
+
return [200, { code: 1, data: [{ id: "d1", domain: "example.com." }] }];
|
|
122
|
+
if (urlPath.startsWith("/record/"))
|
|
123
|
+
return [200, { code: 1, data: recs.map((r) => { const rr = r; return { ...rr, record_id: rr.id, host: rr.name }; }) }];
|
|
124
|
+
return [200, { code: 0, data: {} }];
|
|
125
|
+
case "yandex":
|
|
126
|
+
// POST add/edit/del return {success:"ok", record_id}; GET list returns records
|
|
127
|
+
return [200, { success: "ok", records: method === "GET" ? recs.map((r) => { const rr = r; return { record_id: rr.id, fqdn: rr.name, content: rr.value, type: rr.type, ttl: rr.ttl }; }) : [], record_id: method === "POST" ? "1" : undefined }];
|
|
128
|
+
case "he":
|
|
129
|
+
case "henet":
|
|
130
|
+
// dyndns2 push — the spec expects a plain-text "good"/"nochg" line
|
|
131
|
+
return [200, "good 1.2.3.4"];
|
|
132
|
+
case "dnsservices":
|
|
133
|
+
if (urlPath === "/dns")
|
|
134
|
+
return [200, { zones: [{ name: "example.com", domain_id: "d1", service_id: "s1" }] }];
|
|
135
|
+
if (urlPath.startsWith("/service/"))
|
|
136
|
+
return [200, { records: recs ?? [] }];
|
|
137
|
+
return [200, { records: recs ?? [] }];
|
|
138
|
+
case "spaceship":
|
|
139
|
+
return [200, { records: recs ?? [] }];
|
|
140
|
+
case "gcp":
|
|
141
|
+
case "googleclouddns":
|
|
142
|
+
return [200, { rrsets: (recs ?? []).map((r) => ({ name: r.name + ".", type: r.type, ttl: r.ttl ?? 300, rrdatas: [r.value ?? ""] })) }];
|
|
143
|
+
case "rcodezero":
|
|
144
|
+
case "devnomads":
|
|
145
|
+
case "misaka":
|
|
146
|
+
// these return {rrsets} or {recordsets} with nested records[{content}]
|
|
147
|
+
return [200, (p === "misaka" ? { recordsets: (recs ?? []).map((r) => { const rr = r; return { name: rr.name, type: rr.type, ttl: rr.ttl ?? 300, records: [{ content: rr.value, disabled: false }] }; }) } : { rrsets: (recs ?? []).map((r) => { const rr = r; return { name: rr.name + ".", type: rr.type, ttl: rr.ttl ?? 300, records: [{ content: rr.value, disabled: false }] }; }) })];
|
|
148
|
+
case "namecheap":
|
|
149
|
+
return method === "GET" ? [200, "nochg 1.2.3.4"] : [200, "good 1.2.3.4"];
|
|
150
|
+
default:
|
|
151
|
+
return [200, out];
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
const server = createServer((req, res) => {
|
|
155
|
+
let body = "";
|
|
156
|
+
req.on("data", (c) => (body += c));
|
|
157
|
+
req.on("end", () => {
|
|
158
|
+
const url = new URL(req.url ?? "/", "http://localhost");
|
|
159
|
+
const urlPath = url.pathname;
|
|
160
|
+
let reqBody = undefined;
|
|
161
|
+
if (body) {
|
|
162
|
+
try {
|
|
163
|
+
reqBody = JSON.parse(body);
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
reqBody = body;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
state.requests.push({ method: req.method ?? "GET", url: url.pathname + url.search, body: reqBody });
|
|
170
|
+
if (!authOk(req)) {
|
|
171
|
+
res.writeHead(401, { "content-type": "application/json" });
|
|
172
|
+
res.end(JSON.stringify(auth === "basic" ? { error: "unauthorized" } : { success: false, errors: [{ code: 9109, message: "Invalid Token" }] }));
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const method = req.method ?? "GET";
|
|
176
|
+
const segments = url.pathname.split("/").filter(Boolean);
|
|
177
|
+
const trailing = segments.at(-1) ?? "";
|
|
178
|
+
const json = (code, out) => {
|
|
179
|
+
res.writeHead(code, { "content-type": "application/json" });
|
|
180
|
+
res.end(JSON.stringify(out));
|
|
181
|
+
};
|
|
182
|
+
// Zone-lookup dispatch: providers that first resolve the zone id.
|
|
183
|
+
// GET on their lookup endpoint returns a provider-specific envelope.
|
|
184
|
+
if (method === "GET") {
|
|
185
|
+
const z = "example.com";
|
|
186
|
+
// hover: GET /signin → set-cookie hover_session (then auth.json)
|
|
187
|
+
if (opts.provider === "hover" && urlPath === "/signin") {
|
|
188
|
+
res.writeHead(200, { "content-type": "text/html", "set-cookie": "hover_session=mock-sess; Path=/; HttpOnly" });
|
|
189
|
+
res.end("<html><body>ok</body></html>");
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (opts.provider === "hover" && urlPath.startsWith("/control_panel/dns")) {
|
|
193
|
+
return json(200, { domain: { dns: state.records.map((r) => ({ id: r.id, type: r.type, name: r.name, content: r.value, ttl: r.ttl ?? 300 })) } });
|
|
194
|
+
}
|
|
195
|
+
// euserv: GET /index.php?subaction=... → HTML state machine (login → choose → dns)
|
|
196
|
+
if (opts.provider === "euserv" && urlPath === "/index.php") {
|
|
197
|
+
const q = Object.fromEntries(url.searchParams);
|
|
198
|
+
const subaction = String(q.subaction ?? "");
|
|
199
|
+
if (subaction === "login") {
|
|
200
|
+
res.writeHead(200, { "content-type": "text/html" });
|
|
201
|
+
res.end("<html><body><table><tr><td>ord_no=123</td></tr></table></body></html>");
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (subaction === "choose_order") {
|
|
205
|
+
res.writeHead(200, { "content-type": "text/html" });
|
|
206
|
+
res.end("<html><body>choose</body></html>");
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (subaction === "kc2_domain_dns_get_records") {
|
|
210
|
+
const rows = state.records.map((r) => `<tr><td>${r.name}</td><td>${r.type}</td><td>${r.value}</td></tr>`).join("");
|
|
211
|
+
res.writeHead(200, { "content-type": "text/html" });
|
|
212
|
+
res.end(`<html><body><table>${rows}</table></body></html>`);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (subaction === "kc2_domain_dns_set") {
|
|
216
|
+
const action = String(q.dns_action ?? "");
|
|
217
|
+
if (action === "new") {
|
|
218
|
+
state.records.push({ id: String(state.records.length + 1), type: String(q.dns_type ?? ""), name: String(q.dns_name ?? ""), value: String(q.dns_content ?? ""), ttl: undefined });
|
|
219
|
+
}
|
|
220
|
+
if (action === "del") {
|
|
221
|
+
const id = String(q.dns_id ?? "");
|
|
222
|
+
state.records = state.records.filter((r) => r.id !== id);
|
|
223
|
+
}
|
|
224
|
+
if (action === "mod") {
|
|
225
|
+
const ex = state.records.find((r) => r.id === String(q.dns_id ?? ""));
|
|
226
|
+
if (ex) {
|
|
227
|
+
if (q.dns_content)
|
|
228
|
+
ex.value = String(q.dns_content);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
res.writeHead(200, { "content-type": "text/html" });
|
|
232
|
+
res.end("<html><body>ok</body></html>");
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
res.writeHead(200, { "content-type": "text/html" });
|
|
236
|
+
res.end("<html><body>ok</body></html>");
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
// easyname: GET /en/login → CSRF-TOKEN cookie; GET dns index → HTML table
|
|
240
|
+
if (opts.provider === "easyname" && urlPath === "/en/login") {
|
|
241
|
+
res.writeHead(200, { "content-type": "text/html", "set-cookie": "CSRF-TOKEN=mock-csrf; Path=/; SameSite=Lax" });
|
|
242
|
+
res.end("<html><body>login</body></html>");
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
if (opts.provider === "easyname" && urlPath.includes("/en/domain/dns/index/")) {
|
|
246
|
+
const rows = state.records.map((r) => `<tr data-id="${r.id}"><td>${r.name}</td><td>${r.type}</td><td>${r.value}</td></tr>`).join("");
|
|
247
|
+
res.writeHead(200, { "content-type": "text/html" });
|
|
248
|
+
res.end(`<html><body><table>${rows}</table></body></html>`);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
if (opts.provider === "qcloud" && urlPath === "/") {
|
|
252
|
+
try {
|
|
253
|
+
const q = Object.fromEntries(url.searchParams);
|
|
254
|
+
if (q.Action === "DescribeDomainList")
|
|
255
|
+
return json(200, { Response: { DomainList: [{ DomainId: 1 }] } });
|
|
256
|
+
if (q.Action === "DescribeRecordList")
|
|
257
|
+
return json(200, { Response: { RecordList: state.records.map((r) => ({ RecordId: r.id, Type: r.type, Name: r.name.split(".")[0], Value: r.value, TTL: r.ttl ?? 600 })) } });
|
|
258
|
+
if (q.Action === "CreateRecord")
|
|
259
|
+
return json(200, { Response: { RecordId: 9 } });
|
|
260
|
+
if (q.Action === "ModifyRecord" || q.Action === "DeleteRecord")
|
|
261
|
+
return json(200, { Response: {} });
|
|
262
|
+
}
|
|
263
|
+
catch { /* fallthrough */ }
|
|
264
|
+
}
|
|
265
|
+
if (opts.provider === "yandexcloud" && urlPath === "/zones")
|
|
266
|
+
return json(200, { zones: [{ id: "z1" }] });
|
|
267
|
+
if (opts.provider === "yandexcloud" && urlPath.includes(":listRecordSets"))
|
|
268
|
+
return json(200, { recordSets: state.records.map((r) => ({ id: r.id, fqdn: r.name.endsWith(".") ? r.name : r.name + ".", type: r.type, ttl: r.ttl ?? 300, data: [r.value] })) });
|
|
269
|
+
// ultradns: GET /zones/{zone}./rrsets → {rrsets:[{ownerName,rrtype,rdata,ttl}]}
|
|
270
|
+
if (opts.provider === "ultradns" && urlPath.includes("/rrsets") && !/\/rrsets\//.test(urlPath))
|
|
271
|
+
return json(200, { rrsets: state.records.map((r) => ({ ownerName: r.name.endsWith(".") ? r.name : r.name + ".", rrtype: r.type, rdata: [r.value], ttl: r.ttl ?? 300 })) });
|
|
272
|
+
// powerdns: GET /zones/{zone}. → {records:[{name,type,content,ttl}]}
|
|
273
|
+
if (opts.provider === "powerdns" && /\/zones\/[^/]+$/.test(urlPath))
|
|
274
|
+
return json(200, { records: state.records.map((r) => ({ name: r.name.endsWith(".") ? r.name : r.name + ".", type: r.type, content: r.value, ttl: r.ttl ?? 300 })) });
|
|
275
|
+
// OCI: GET /zones/{zone}/records → {items:[{domain,rtype,rdata,ttl}]}
|
|
276
|
+
if (opts.provider === "oci" && /\/zones\/[^/]+\/records/.test(urlPath)) {
|
|
277
|
+
return json(200, { items: state.records.map((r) => ({ domain: r.name, rtype: r.type, rdata: r.value, ttl: r.ttl ?? 300 })) });
|
|
278
|
+
}
|
|
279
|
+
// infoblox: GET record:a?name~= → array [{_ref,name,ipv4addr,ttl}]
|
|
280
|
+
if (opts.provider === "infoblox" && urlPath.includes("/record:")) {
|
|
281
|
+
return json(200, state.records.map((r) => ({ _ref: r.id, name: r.name.endsWith(".") ? r.name : r.name + ".", ipv4addr: r.value, ttl: r.ttl ?? 300 })));
|
|
282
|
+
}
|
|
283
|
+
// azure: GET /subscriptions/.../dnsZones/{zone}/recordsets → {value:[...]}
|
|
284
|
+
if (opts.provider === "azure" && /\/dnsZones\/[^/]+\/recordsets/.test(urlPath)) {
|
|
285
|
+
return json(200, { value: state.records.map((r) => ({
|
|
286
|
+
id: r.id,
|
|
287
|
+
type: "Microsoft.Network/dnszones/" + r.type,
|
|
288
|
+
name: r.name,
|
|
289
|
+
properties: { TTL: r.ttl ?? 300, ...(r.type === "TXT" ? { TXTRecords: [{ value: [r.value] }] } : { ARecords: [{ ipv4Address: r.value }] }) },
|
|
290
|
+
})) });
|
|
291
|
+
}
|
|
292
|
+
// directadmin: GET /CMD_API_DNS_CONTROL — action in query
|
|
293
|
+
if (opts.provider === "directadmin" && urlPath.endsWith("/CMD_API_DNS_CONTROL")) {
|
|
294
|
+
const q = Object.fromEntries(url.searchParams);
|
|
295
|
+
const action = String(q.action ?? "");
|
|
296
|
+
if (action === "list")
|
|
297
|
+
return json(200, { records: state.records.map((r) => ({ name: r.name.endsWith(".") ? r.name : r.name + ".", type: r.type, value: r.value, ttl: String(r.ttl ?? 300) })) });
|
|
298
|
+
if (action === "add") {
|
|
299
|
+
const nm = String(q.name ?? "").replace(/\.$/, "");
|
|
300
|
+
if (q.type)
|
|
301
|
+
state.records.push({ id: randomUUID(), type: String(q.type), name: nm, value: String(q.value ?? ""), ttl: q.ttl !== undefined ? Number(q.ttl) : undefined });
|
|
302
|
+
return json(200, {});
|
|
303
|
+
}
|
|
304
|
+
if (action === "modify") {
|
|
305
|
+
const nm = String(q.name ?? "").replace(/\.$/, "");
|
|
306
|
+
const ex = state.records.find((r) => r.name === nm);
|
|
307
|
+
if (ex) {
|
|
308
|
+
if (q.value)
|
|
309
|
+
ex.value = String(q.value);
|
|
310
|
+
}
|
|
311
|
+
return json(200, {});
|
|
312
|
+
}
|
|
313
|
+
if (action === "delete") {
|
|
314
|
+
const nm = String(q.name ?? "").replace(/\.$/, "");
|
|
315
|
+
state.records = state.records.filter((r) => !(r.name === nm && r.type === String(q.type ?? "")));
|
|
316
|
+
return json(200, {});
|
|
317
|
+
}
|
|
318
|
+
return json(200, {});
|
|
319
|
+
}
|
|
320
|
+
if (opts.provider === "gehirn" && urlPath === "/zones")
|
|
321
|
+
return json(200, { zones: [{ id: "z1", name: z }] });
|
|
322
|
+
if (opts.provider === "rcodezero" && (urlPath === "/zones/" || urlPath === "/zones"))
|
|
323
|
+
return json(200, { zones: [{ id: "z1", name: z }] });
|
|
324
|
+
if (opts.provider === "devnomads" && (urlPath === "/zones/" || urlPath === "/zones"))
|
|
325
|
+
return json(200, { zones: [{ id: "z1", name: z }] });
|
|
326
|
+
if (opts.provider === "misaka" && urlPath === `/zones/${z}/settings`)
|
|
327
|
+
return json(200, { id: "z1" });
|
|
328
|
+
if (opts.provider === "softlayer" && urlPath.includes("getByDomainName"))
|
|
329
|
+
return json(200, [{ id: 1 }]);
|
|
330
|
+
if ((opts.provider === "linode4" || opts.provider === "linode") && urlPath === "/domains")
|
|
331
|
+
return json(200, { data: [{ id: 1 }] });
|
|
332
|
+
// linode: GET /domains/{zid}/records → {data:[{id,type,name,target,ttl}]}
|
|
333
|
+
if ((opts.provider === "linode" || opts.provider === "linode4") && /\/domains\/[^/]+\/records/.test(urlPath))
|
|
334
|
+
return json(200, { data: state.records.map(apiShape) });
|
|
335
|
+
if (opts.provider === "nfsn" && urlPath.endsWith("/list")) {
|
|
336
|
+
return json(200, state.records.map((r) => ({ id: r.id, type: r.type, name: r.name, data: r.value })));
|
|
337
|
+
}
|
|
338
|
+
// rackspace: GET /{tenant}/domains?name= → {domains}; GET /domains/{id}/records → {records}
|
|
339
|
+
if (opts.provider === "rackspace" && urlPath.endsWith("/domains"))
|
|
340
|
+
return json(200, { domains: [{ id: "d1" }] });
|
|
341
|
+
if (opts.provider === "rackspace" && /\/domains\/[^/]+\/records$/.test(urlPath))
|
|
342
|
+
return json(200, { records: state.records.map(apiShape) });
|
|
343
|
+
// memset: JSON-RPC via GET query — dns.zone_domain_info / zone_info / record_create
|
|
344
|
+
if (opts.provider === "memset") {
|
|
345
|
+
const q = Object.fromEntries(url.searchParams);
|
|
346
|
+
if (urlPath.endsWith("dns.zone_domain_info"))
|
|
347
|
+
return json(200, { zone_id: "z1" });
|
|
348
|
+
if (urlPath.endsWith("dns.zone_info"))
|
|
349
|
+
return json(200, { records: state.records.map(apiShape) });
|
|
350
|
+
if (urlPath.endsWith("dns.zone_record_create")) {
|
|
351
|
+
state.records.push({ id: randomUUID(), type: String(q.type ?? ""), name: String(q.name ?? ""), value: String(q.content ?? q.data ?? ""), ttl: q.ttl !== undefined ? Number(q.ttl) : undefined });
|
|
352
|
+
return json(200, { id: String(state.records.length) });
|
|
353
|
+
}
|
|
354
|
+
if (urlPath.endsWith("dns.zone_record_update"))
|
|
355
|
+
return json(200, { ok: true });
|
|
356
|
+
if (urlPath.endsWith("dns.zone_record_delete")) {
|
|
357
|
+
state.records = state.records.filter((r) => r.id !== String(q.id ?? ""));
|
|
358
|
+
return json(200, { ok: true });
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
const listOut = { records: state.records.map(apiShape) };
|
|
363
|
+
// dreamhost (cmd=dns-add_record) / namesilo (dnsAddRecord) create via GET
|
|
364
|
+
const cmd = url.searchParams.get("cmd") ?? url.pathname.split("/").pop() ?? "";
|
|
365
|
+
if (method === "GET" && /add[_-]?record/i.test(cmd) && !/list/i.test(cmd)) {
|
|
366
|
+
// namesilo: params are rrtype/rrhost/rrvalue and the API has ?type=json
|
|
367
|
+
// (format); dreamhost: cmd=dns-add_record&type=<real>&record=&value=
|
|
368
|
+
const isNamesilo = opts.provider === "namesilo";
|
|
369
|
+
const rec = {
|
|
370
|
+
type: (isNamesilo ? url.searchParams.get("rrtype") : url.searchParams.get("type")) ?? "A",
|
|
371
|
+
name: (isNamesilo ? url.searchParams.get("rrhost") : url.searchParams.get("record")) ?? "verify.example.com",
|
|
372
|
+
value: (isNamesilo ? url.searchParams.get("rrvalue") : url.searchParams.get("value")) ?? "v1",
|
|
373
|
+
};
|
|
374
|
+
const full = rec.name.includes(".") ? rec.name : `${rec.name}.example.com`;
|
|
375
|
+
const created = { id: randomUUID(), type: rec.type, name: rec.name.endsWith(".") ? rec.name.slice(0, -1) : full, value: rec.value, ttl: 300 };
|
|
376
|
+
state.records.push(created);
|
|
377
|
+
const [c, b] = formatFor(opts.provider, method, url.pathname, listOut);
|
|
378
|
+
return json(c, b);
|
|
379
|
+
}
|
|
380
|
+
const [code, bodyOut] = formatFor(opts.provider, method, url.pathname, listOut);
|
|
381
|
+
if (method === "GET") {
|
|
382
|
+
if (typeof bodyOut === "string") {
|
|
383
|
+
res.writeHead(200, { "content-type": "text/plain" });
|
|
384
|
+
res.end(bodyOut);
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
return json(code, bodyOut);
|
|
388
|
+
}
|
|
389
|
+
if (method === "POST") {
|
|
390
|
+
const ct = (req.headers["content-type"] ?? "").toLowerCase();
|
|
391
|
+
const urlPath = url.pathname;
|
|
392
|
+
// hover: POST /signin/auth.json → set-cookie hoverauth
|
|
393
|
+
if (opts.provider === "hover" && urlPath === "/signin/auth.json") {
|
|
394
|
+
res.writeHead(200, { "content-type": "application/json", "set-cookie": "hoverauth=mock-auth; Path=/; HttpOnly" });
|
|
395
|
+
res.end(JSON.stringify({ /* hover expects 200 with auth cookie */}, null, 0));
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
if (opts.provider === "hover" && urlPath.startsWith("/control_panel/dns")) {
|
|
399
|
+
const hb = (() => { if (body) {
|
|
400
|
+
try {
|
|
401
|
+
return JSON.parse(body);
|
|
402
|
+
}
|
|
403
|
+
catch {
|
|
404
|
+
return {};
|
|
405
|
+
}
|
|
406
|
+
} return {}; })();
|
|
407
|
+
// GET /control_panel/dns/{zone} → {domain:{dns:[...]}}; POST → create
|
|
408
|
+
const rec = stdRec(hb);
|
|
409
|
+
if (method === "POST") {
|
|
410
|
+
if (rec.name)
|
|
411
|
+
state.records.push({ id: randomUUID(), type: rec.type, name: rec.name, value: rec.value, ttl: rec.ttl });
|
|
412
|
+
return json(200, { id: state.records.at(-1)?.id ?? `${rec.name}/${rec.type}` });
|
|
413
|
+
}
|
|
414
|
+
return json(200, {});
|
|
415
|
+
}
|
|
416
|
+
// easyname: POST /en/authentication-api/login → set-cookie session + 200
|
|
417
|
+
if (opts.provider === "easyname" && urlPath === "/en/authentication-api/login") {
|
|
418
|
+
res.writeHead(200, { "content-type": "application/json", "set-cookie": "JSESSIONID=mock-session; Path=/; HttpOnly" });
|
|
419
|
+
res.end(JSON.stringify({ ok: true }));
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
if (opts.provider === "easyname" && urlPath.includes("/en/domain/dns/")) {
|
|
423
|
+
const eb = (() => { if (body) {
|
|
424
|
+
try {
|
|
425
|
+
return JSON.parse(body);
|
|
426
|
+
}
|
|
427
|
+
catch {
|
|
428
|
+
return Object.fromEntries(new URLSearchParams(body));
|
|
429
|
+
}
|
|
430
|
+
} return {}; })();
|
|
431
|
+
// easyname parses record ids via /data-id="?([0-9]+)"? — the id must be numeric
|
|
432
|
+
if (urlPath.includes("/create/")) {
|
|
433
|
+
const rec = stdRec(eb);
|
|
434
|
+
if (rec.name)
|
|
435
|
+
state.records.push({ id: String(state.records.length + 1), type: rec.type, name: rec.name, value: rec.value, ttl: rec.ttl });
|
|
436
|
+
}
|
|
437
|
+
if (urlPath.includes("/edit/")) {
|
|
438
|
+
const rec = stdRec(eb);
|
|
439
|
+
const ex = state.records.find((r) => r.id === String(eb.id ?? "") || r.name === rec.name);
|
|
440
|
+
if (ex) {
|
|
441
|
+
if (rec.value)
|
|
442
|
+
ex.value = rec.value;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
if (urlPath.includes("/delete/")) {
|
|
446
|
+
const id = String(eb.id ?? urlPath.split("/id/")[1] ?? urlPath.split("/id/")[1]?.split("/")[0] ?? "");
|
|
447
|
+
state.records = state.records.filter((r) => r.id !== id);
|
|
448
|
+
}
|
|
449
|
+
res.writeHead(200, { "content-type": "text/html" });
|
|
450
|
+
res.end("<html><body>ok</body></html>");
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
// gransy: SOAP XML POST /wsdl — op from soapaction header / <op> element
|
|
454
|
+
if (opts.provider === "gransy" && urlPath.endsWith("/wsdl")) {
|
|
455
|
+
const soapaction = String(req.headers["soapaction"] ?? "");
|
|
456
|
+
const xml = String(body ?? "");
|
|
457
|
+
const op = /xmlns=\"https:\/\/subreg.cz\">([^<]+)</.exec(xml)?.[1] ?? soapaction.split(":").pop() ?? soapaction;
|
|
458
|
+
const wrap = (inner) => `<?xml version=\"1.0\" encoding=\"UTF-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body>${inner}</soap:Body></soap:Envelope>`;
|
|
459
|
+
if (/Login/.test(op)) {
|
|
460
|
+
res.writeHead(200, { "content-type": "text/xml" });
|
|
461
|
+
res.end(wrap("<LoginResponse><status>ok</status></LoginResponse>"));
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
if (/Get_DNS_Zone/.test(op)) {
|
|
465
|
+
const rows = state.records.map((r) => `<record><id>${r.id}</id><type>${r.type}</type><name>${r.name}</name><rdata>${r.value}</rdata></record>`).join("");
|
|
466
|
+
res.writeHead(200, { "content-type": "text/xml" });
|
|
467
|
+
res.end(wrap(`<Get_DNS_ZoneResponse>${rows}</Get_DNS_ZoneResponse>`));
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
if (/Add_DNS_Record/.test(op)) {
|
|
471
|
+
const m = /<name>([^<]*)<\/name>/.exec(xml);
|
|
472
|
+
const t = /<type>([^<]*)<\/type>/.exec(xml);
|
|
473
|
+
const d = /<rdata>([^<]*)<\/rdata>/.exec(xml);
|
|
474
|
+
if (t?.[1])
|
|
475
|
+
state.records.push({ id: String(state.records.length + 1), type: t[1], name: m?.[1] ?? "", value: d?.[1] ?? "", ttl: undefined });
|
|
476
|
+
res.writeHead(200, { "content-type": "text/xml" });
|
|
477
|
+
res.end(wrap("<Add_DNS_RecordResponse><status>ok</status></Add_DNS_RecordResponse>"));
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
if (/Modify_DNS_Record/.test(op)) {
|
|
481
|
+
res.writeHead(200, { "content-type": "text/xml" });
|
|
482
|
+
res.end(wrap("<Modify_DNS_RecordResponse><status>ok</status></Modify_DNS_RecordResponse>"));
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
if (/Delete_DNS_Record/.test(op)) {
|
|
486
|
+
const m = /<id>([^<]*)<\/id>/.exec(xml);
|
|
487
|
+
const id = m?.[1] ?? "";
|
|
488
|
+
state.records = state.records.filter((r) => r.id !== id);
|
|
489
|
+
res.writeHead(200, { "content-type": "text/xml" });
|
|
490
|
+
res.end(wrap("<Delete_DNS_RecordResponse><status>ok</status></Delete_DNS_RecordResponse>"));
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
res.writeHead(200, { "content-type": "text/xml" });
|
|
494
|
+
res.end(wrap("<status>ok</status>"));
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
// plesk: XML body (<site><get>|<dns><get_rec>|<add_rec>|<del_rec>|…)
|
|
498
|
+
if (opts.provider === "plesk" && String(body ?? "").includes("<packet>")) {
|
|
499
|
+
const xml = String(body ?? "");
|
|
500
|
+
res.writeHead(200, { "content-type": "text/xml" });
|
|
501
|
+
if (/<site><get>/.test(xml)) {
|
|
502
|
+
res.end("<?xml version=\"1.0\"?><packet><site><get><result><id>#S1</id><status>ok</status></result></get></site></packet>");
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
if (/<dns><get_rec>/.test(xml)) {
|
|
506
|
+
const rows = state.records.map((r) => { const host = r.name === "example.com" ? "@" : r.name.replace(".example.com", ""); return `<rec><id>${r.id}</id><type>${r.type}</type><host>${host}</host><value>${r.value}</value></rec>`; });
|
|
507
|
+
res.end(`<?xml version=\"1.0\"?><packet><dns><get_rec><result><status>ok</status>${rows.join("")}</result></get_rec></dns></packet>`);
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
if (/<dns><add_rec>/.test(xml)) {
|
|
511
|
+
const m = /<host>([^<]*)<\/host>/.exec(xml);
|
|
512
|
+
const t = /<type>([^<]*)<\/type>/.exec(xml);
|
|
513
|
+
const v = /<value>([^<]*)<\/value>/.exec(xml);
|
|
514
|
+
const host = m?.[1] ?? "";
|
|
515
|
+
const name = host === "@" ? "example.com" : `${host}.example.com`;
|
|
516
|
+
if (t?.[1])
|
|
517
|
+
state.records.push({ id: randomUUID(), type: t[1], name, value: v?.[1] ?? "", ttl: undefined });
|
|
518
|
+
res.end("<?xml version=\"1.0\"?><packet><dns><add_rec><result><status>ok</status></result></add_rec></dns></packet>");
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
if (/<dns><set_rec>/.test(xml)) {
|
|
522
|
+
res.end("<?xml version=\"1.0\"?><packet><dns><set_rec><result><status>ok</status></result></set_rec></dns></packet>");
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
if (/<dns><del_rec>/.test(xml)) {
|
|
526
|
+
const m = /<id>([^<]*)<\/id>/.exec(xml);
|
|
527
|
+
const id = m?.[1] ?? "";
|
|
528
|
+
state.records = state.records.filter((r) => r.id !== id);
|
|
529
|
+
res.end("<?xml version=\"1.0\"?><packet><dns><del_rec><result><status>ok</status></result></del_rec></dns></packet>");
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
res.end("<?xml version=\"1.0\"?><packet><status>ok</status></packet>");
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
const authBody = (() => {
|
|
536
|
+
if (body) {
|
|
537
|
+
try {
|
|
538
|
+
return JSON.parse(body);
|
|
539
|
+
}
|
|
540
|
+
catch {
|
|
541
|
+
return Object.fromEntries(new URLSearchParams(body));
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
return {};
|
|
545
|
+
})();
|
|
546
|
+
// qcloud (Tencent DNSPod): POST / with JSON body containing Action
|
|
547
|
+
if (opts.provider === "qcloud") {
|
|
548
|
+
const action = String(req.headers["x-tc-action"] ?? "").toLowerCase();
|
|
549
|
+
if (action === "describedomainlist")
|
|
550
|
+
return json(200, { Response: { DomainList: [{ DomainId: 1 }] } });
|
|
551
|
+
if (action === "describerecordlist")
|
|
552
|
+
return json(200, { Response: { RecordList: state.records.map((r) => ({ RecordId: r.id, Type: r.type, Name: r.name.split(".")[0], Value: r.value, TTL: r.ttl ?? 600 })) } });
|
|
553
|
+
if (action === "createrecord") {
|
|
554
|
+
const rec = stdRec(authBody);
|
|
555
|
+
if (rec.name)
|
|
556
|
+
state.records.push({ id: String(state.records.length + 1), type: rec.type || "A", name: rec.name, value: rec.value, ttl: rec.ttl });
|
|
557
|
+
return json(200, { Response: { RecordId: 9 } });
|
|
558
|
+
}
|
|
559
|
+
if (action === "modifyrecord" || action === "deleterecord")
|
|
560
|
+
return json(200, { Response: {} });
|
|
561
|
+
}
|
|
562
|
+
// wedos: POST /wapi/json with form-encoded {request=<urlencoded JSON>}
|
|
563
|
+
if (opts.provider === "wedos") {
|
|
564
|
+
const form = Object.fromEntries(new URLSearchParams(String(body ?? "")));
|
|
565
|
+
const reqObj = (JSON.parse(String(form.request ?? "{}")).request ?? JSON.parse(String(form.request ?? "{}")));
|
|
566
|
+
const cmd = reqObj.command ?? "";
|
|
567
|
+
if (cmd === "dns-domains-list")
|
|
568
|
+
return json(200, { response: { code: 1000, data: { domain: [{ name: "example.com" }] } } });
|
|
569
|
+
if (cmd === "dns-rows-list")
|
|
570
|
+
return json(200, { response: { code: 1000, data: { row: state.records.map((r) => ({ ID: r.id, name: r.name, rdtype: r.type, rdata: r.value, ttl: r.ttl ?? 300 })) } } });
|
|
571
|
+
if (cmd.startsWith("dns-row-add")) {
|
|
572
|
+
const rec = stdRec(reqObj.data);
|
|
573
|
+
if (rec.name)
|
|
574
|
+
state.records.push({ id: randomUUID(), type: rec.type, name: rec.name, value: rec.value, ttl: rec.ttl });
|
|
575
|
+
return json(200, { response: { code: 1000, data: { id: "1" } } });
|
|
576
|
+
}
|
|
577
|
+
if (cmd.startsWith("dns-row-update"))
|
|
578
|
+
return json(200, { response: { code: 1000, data: {} } });
|
|
579
|
+
if (cmd.startsWith("dns-row-delete"))
|
|
580
|
+
return json(200, { response: { code: 1000, data: {} } });
|
|
581
|
+
return json(200, { response: { code: 1000, data: {} } });
|
|
582
|
+
}
|
|
583
|
+
// nfsn: GET|POST /dns/{zone}/list|add|replace|remove (POST body = JSON)
|
|
584
|
+
if (opts.provider === "nfsn" && urlPath.includes("/dns/")) {
|
|
585
|
+
if (urlPath.endsWith("/add")) {
|
|
586
|
+
const rec = stdRec(authBody);
|
|
587
|
+
if (rec.name)
|
|
588
|
+
state.records.push({ id: randomUUID(), type: rec.type, name: rec.name, value: rec.value, ttl: rec.ttl });
|
|
589
|
+
return json(200, { id: "1" });
|
|
590
|
+
}
|
|
591
|
+
if (urlPath.endsWith("/replace"))
|
|
592
|
+
return json(200, { id: "1" });
|
|
593
|
+
if (urlPath.endsWith("/remove")) {
|
|
594
|
+
const delId = String(stdRec(authBody).name ?? "");
|
|
595
|
+
state.records = state.records.filter((r) => (r.id !== delId && r.name !== delId));
|
|
596
|
+
return json(200, {});
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
// gratisdns: POST form {action:list|add|...} — list returns records
|
|
600
|
+
if (opts.provider === "gratisdns" && authBody.action === "list") {
|
|
601
|
+
return json(200, { data: state.records.map(apiShape) });
|
|
602
|
+
}
|
|
603
|
+
// token endpoints: ultradns (grant_type=password), dnsservices (/login)
|
|
604
|
+
if (opts.provider === "ultradns" && urlPath.includes("/authorization/token")) {
|
|
605
|
+
return json(200, { access_token: "tok-1" });
|
|
606
|
+
}
|
|
607
|
+
if (opts.provider === "dnsservices" && urlPath === "/login") {
|
|
608
|
+
return json(200, { token: "tok-1" });
|
|
609
|
+
}
|
|
610
|
+
if (opts.provider === "azure" && urlPath.includes("oauth2")) {
|
|
611
|
+
return json(200, { access_token: "tok-1" });
|
|
612
|
+
}
|
|
613
|
+
if (opts.provider === "rackspace" && urlPath.includes("tokens")) {
|
|
614
|
+
return json(200, { access: { token: { id: "tok-1" }, user: { tenantId: "t1" } } });
|
|
615
|
+
}
|
|
616
|
+
if (opts.provider === "rackspace" && urlPath.endsWith("/domains")) {
|
|
617
|
+
return json(200, { domains: [{ id: "d1" }] });
|
|
618
|
+
}
|
|
619
|
+
if (opts.provider === "oci" && urlPath.includes("authorization/token")) {
|
|
620
|
+
return json(200, { access_token: "tok-1" });
|
|
621
|
+
}
|
|
622
|
+
if (opts.provider === "transip" && urlPath === "/auth") {
|
|
623
|
+
return json(200, { token: "tok-1" });
|
|
624
|
+
}
|
|
625
|
+
// ultradns: POST /authorization/token → {access_token}
|
|
626
|
+
if (opts.provider === "ultradns" && urlPath.includes("/authorization/token")) {
|
|
627
|
+
return json(200, { access_token: "tok-1" });
|
|
628
|
+
}
|
|
629
|
+
// googleclouddns: POST /oauth2/gcp → {access_token} (JWT exchange)
|
|
630
|
+
if (opts.provider === "googleclouddns" && urlPath.includes("/oauth2/")) {
|
|
631
|
+
return json(200, { access_token: "tok-1" });
|
|
632
|
+
}
|
|
633
|
+
// cloudxns: POST /record with JSON body → {code:1, data:{id}}
|
|
634
|
+
if (opts.provider === "cloudxns" && urlPath === "/record") {
|
|
635
|
+
const crec = stdRec(body);
|
|
636
|
+
if (crec.name)
|
|
637
|
+
state.records.push({ id: String(state.records.length + 1), type: crec.type, name: crec.name, value: crec.value, ttl: crec.ttl });
|
|
638
|
+
return json(200, { code: 1, data: { id: String(state.records.length) } });
|
|
639
|
+
}
|
|
640
|
+
// joker: text protocol — /login → auth-sid=.., /dns-zone-get → data rows
|
|
641
|
+
if (opts.provider === "joker") {
|
|
642
|
+
if (urlPath.endsWith("/login")) {
|
|
643
|
+
res.writeHead(200, { "content-type": "text/plain" });
|
|
644
|
+
res.end("auth-sid=sid-1\n\n");
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
if (urlPath.endsWith("/dns-zone-get")) {
|
|
648
|
+
const lines = state.records.map((r) => { const label = r.name === "example.com" ? "@" : r.name.replace(".example.com", ""); return `${label} ${r.type} ${r.value} ${r.ttl ?? 300}`; });
|
|
649
|
+
res.writeHead(200, { "content-type": "text/plain" });
|
|
650
|
+
res.end("# joker\n\n" + lines.join("\n") + "\n");
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
if (urlPath.endsWith("/dns-zone-add")) {
|
|
654
|
+
const q = Object.fromEntries(new URLSearchParams(String(body ?? "")));
|
|
655
|
+
const label = String(q.label ?? "");
|
|
656
|
+
const name = label === "@" || label === "" ? "example.com" : `${label}.example.com`;
|
|
657
|
+
if (q.type)
|
|
658
|
+
state.records.push({ id: randomUUID(), type: String(q.type), name, value: String(q.target ?? ""), ttl: q.ttl !== undefined ? Number(q.ttl) : undefined });
|
|
659
|
+
res.writeHead(200, { "content-type": "text/plain" });
|
|
660
|
+
res.end("ok\n");
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
if (urlPath.endsWith("/dns-zone-delete")) {
|
|
664
|
+
const q = Object.fromEntries(new URLSearchParams(String(body ?? "")));
|
|
665
|
+
const label = String(q.label ?? "");
|
|
666
|
+
const name = label === "@" || label === "" ? "example.com" : `${label}.example.com`;
|
|
667
|
+
state.records = state.records.filter((r) => !(r.name === name && r.type === String(q.type ?? "")));
|
|
668
|
+
res.writeHead(200, { "content-type": "text/plain" });
|
|
669
|
+
res.end("ok\n");
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
672
|
+
if (urlPath.endsWith("/dns-zone-edit")) {
|
|
673
|
+
const q = Object.fromEntries(new URLSearchParams(String(body ?? "")));
|
|
674
|
+
const label = String(q.label ?? "");
|
|
675
|
+
const name = label === "@" || label === "" ? "example.com" : `${label}.example.com`;
|
|
676
|
+
const ex = state.records.find((r) => r.name === name && r.type === String(q.type ?? ""));
|
|
677
|
+
if (ex) {
|
|
678
|
+
if (q.target)
|
|
679
|
+
ex.value = String(q.target);
|
|
680
|
+
}
|
|
681
|
+
res.writeHead(200, { "content-type": "text/plain" });
|
|
682
|
+
res.end("ok\n");
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
res.writeHead(200, { "content-type": "text/plain" });
|
|
686
|
+
res.end("ok\n");
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
689
|
+
// dinahosting: POST form {cmd:...} → {records} (list) or success (mutate)
|
|
690
|
+
if (opts.provider === "dinahosting") {
|
|
691
|
+
const cmd = String(authBody.cmd ?? "");
|
|
692
|
+
if (cmd === "dns_zone_info")
|
|
693
|
+
return json(200, { records: state.records.map(apiShape) });
|
|
694
|
+
if (cmd === "dns_zone_add_record") {
|
|
695
|
+
const rec = stdRec(authBody);
|
|
696
|
+
if (rec.name)
|
|
697
|
+
state.records.push({ id: randomUUID(), type: rec.type, name: rec.name, value: rec.value, ttl: rec.ttl });
|
|
698
|
+
return json(200, {});
|
|
699
|
+
}
|
|
700
|
+
if (cmd === "dns_zone_modify_record") {
|
|
701
|
+
const rec = stdRec(authBody);
|
|
702
|
+
const ex = state.records.find((r) => r.id === String(authBody.id ?? ""));
|
|
703
|
+
if (ex) {
|
|
704
|
+
if (rec.value)
|
|
705
|
+
ex.value = rec.value;
|
|
706
|
+
if (rec.type)
|
|
707
|
+
ex.type = rec.type;
|
|
708
|
+
}
|
|
709
|
+
return json(200, {});
|
|
710
|
+
}
|
|
711
|
+
if (cmd === "dns_zone_delete_record") {
|
|
712
|
+
const id = String(authBody.id ?? "");
|
|
713
|
+
state.records = state.records.filter((r) => r.id !== id);
|
|
714
|
+
return json(200, {});
|
|
715
|
+
}
|
|
716
|
+
return json(200, {});
|
|
717
|
+
}
|
|
718
|
+
// hostingde/httpnet: POST recordsFind (list) — return the current records
|
|
719
|
+
if ((opts.provider === "hostingde" || opts.provider === "httpnet") && urlPath.endsWith("recordsFind")) {
|
|
720
|
+
return json(200, { status: "success", data: { records: state.records.map(apiShape) } });
|
|
721
|
+
}
|
|
722
|
+
// hostingde/httpnet: POST recordsCreate — nested {records:[...]}
|
|
723
|
+
if ((opts.provider === "hostingde" || opts.provider === "httpnet") && urlPath.endsWith("recordsCreate")) {
|
|
724
|
+
const recs0 = (authBody.records ?? []);
|
|
725
|
+
for (const r of recs0) {
|
|
726
|
+
const rr = stdRec(r);
|
|
727
|
+
if (rr.name)
|
|
728
|
+
state.records.push({ id: randomUUID(), type: rr.type, name: rr.name, value: rr.value, ttl: rr.ttl });
|
|
729
|
+
}
|
|
730
|
+
return json(200, { status: "success", data: { records: state.records.map(apiShape) } });
|
|
731
|
+
}
|
|
732
|
+
if ((opts.provider === "hostingde" || opts.provider === "httpnet") && urlPath.endsWith("recordsUpdate")) {
|
|
733
|
+
const recs0 = (authBody.records ?? []);
|
|
734
|
+
for (const r of recs0) {
|
|
735
|
+
const rr = stdRec(r);
|
|
736
|
+
const ex = state.records.find((x) => x.id === String(rr.name ?? "") || x.id === String(r.id));
|
|
737
|
+
if (ex && rr.value)
|
|
738
|
+
ex.value = rr.value;
|
|
739
|
+
if (rr.type)
|
|
740
|
+
ex.type = rr.type;
|
|
741
|
+
if (rr.ttl !== undefined)
|
|
742
|
+
ex.ttl = rr.ttl;
|
|
743
|
+
}
|
|
744
|
+
return json(200, { status: "success", data: { records: state.records.map(apiShape) } });
|
|
745
|
+
}
|
|
746
|
+
if ((opts.provider === "hostingde" || opts.provider === "httpnet") && urlPath.endsWith("recordsDelete")) {
|
|
747
|
+
const recs0 = (authBody.records ?? []);
|
|
748
|
+
for (const r of recs0) {
|
|
749
|
+
const id = String(r.id ?? "");
|
|
750
|
+
state.records = state.records.filter((x) => x.id !== id);
|
|
751
|
+
}
|
|
752
|
+
return json(200, { status: "success", data: { records: [] } });
|
|
753
|
+
}
|
|
754
|
+
// rackspace: POST /domains/{id}/records with {records:[...]}
|
|
755
|
+
if (opts.provider === "rackspace" && /\/domains\/[^/]+\/records$/.test(urlPath)) {
|
|
756
|
+
const rs = (authBody.records ?? []);
|
|
757
|
+
const ids = [];
|
|
758
|
+
for (const r of rs) {
|
|
759
|
+
const rr = stdRec(r);
|
|
760
|
+
const created = { id: randomUUID(), type: rr.type, name: rr.name, value: rr.value, ttl: rr.ttl };
|
|
761
|
+
if (rr.name)
|
|
762
|
+
state.records.push(created);
|
|
763
|
+
ids.push(created.id);
|
|
764
|
+
}
|
|
765
|
+
return json(200, { records: ids.map((id) => ({ id })) });
|
|
766
|
+
}
|
|
767
|
+
// yandexcloud: POST /zones/{zid}:upsertRecordSets — upsertions / deletions
|
|
768
|
+
if (opts.provider === "yandexcloud" && urlPath.includes(":upsertRecordSets")) {
|
|
769
|
+
const ups = (authBody.upsertions ?? []);
|
|
770
|
+
for (const u of ups) {
|
|
771
|
+
const nm = String(u.name ?? "").replace(/\.$/, "");
|
|
772
|
+
const tp = String(u.type ?? "");
|
|
773
|
+
const dt = u.data ?? [];
|
|
774
|
+
const ex = state.records.find((r) => r.name === nm && r.type === tp);
|
|
775
|
+
if (ex) {
|
|
776
|
+
ex.value = dt[0] ?? ex.value;
|
|
777
|
+
if (u.ttl !== undefined)
|
|
778
|
+
ex.ttl = Number(u.ttl);
|
|
779
|
+
}
|
|
780
|
+
else if (nm)
|
|
781
|
+
state.records.push({ id: randomUUID(), type: tp, name: nm, value: dt[0] ?? "", ttl: u.ttl !== undefined ? Number(u.ttl) : undefined });
|
|
782
|
+
}
|
|
783
|
+
const dels = (authBody.deletions ?? []);
|
|
784
|
+
for (const d of dels) {
|
|
785
|
+
const nm = String(d.name ?? "").replace(/\.$/, "");
|
|
786
|
+
state.records = state.records.filter((r) => !(r.name === nm && r.type === String(d.type ?? "")));
|
|
787
|
+
}
|
|
788
|
+
return json(200, {});
|
|
789
|
+
}
|
|
790
|
+
// yandex: POST add with form query (subdomain + domain) → {success:"ok", record_id}
|
|
791
|
+
if (opts.provider === "yandex") {
|
|
792
|
+
const q = Object.fromEntries(new URLSearchParams(String(body ?? "")));
|
|
793
|
+
const sub = String(q.subdomain ?? "");
|
|
794
|
+
const dom = String(q.domain ?? "example.com");
|
|
795
|
+
const name = sub === "@" || sub === "" ? dom : `${sub}.${dom}`;
|
|
796
|
+
if (q.type)
|
|
797
|
+
state.records.push({ id: String(state.records.length + 1), type: String(q.type), name, value: String(q.content ?? q.value ?? ""), ttl: q.ttl !== undefined ? Number(q.ttl) : undefined });
|
|
798
|
+
return json(200, { success: "ok", record_id: name && q.type ? String(state.records.length) : undefined });
|
|
799
|
+
}
|
|
800
|
+
let bodyObj = authBody;
|
|
801
|
+
if (opts.provider === "netcup" && bodyObj.action) {
|
|
802
|
+
if (bodyObj.action === "login")
|
|
803
|
+
return json(200, { status: "success", responsedata: { apisessionid: "sid-1" } });
|
|
804
|
+
if (bodyObj.action === "logout")
|
|
805
|
+
return json(200, { status: "success" });
|
|
806
|
+
if (bodyObj.action.startsWith("info"))
|
|
807
|
+
return json(200, { status: "success", responsedata: { dnsrecords: state.records.map(apiShape) } });
|
|
808
|
+
if (bodyObj.action === "updateDnsRecords") {
|
|
809
|
+
const set = bodyObj.param?.dnsrecordset?.dnsrecords ?? [];
|
|
810
|
+
for (const dr of set) {
|
|
811
|
+
const rec = stdRec(dr);
|
|
812
|
+
const created = { id: randomUUID(), type: rec.type, name: rec.name, value: rec.value, ttl: rec.ttl };
|
|
813
|
+
if (rec.name)
|
|
814
|
+
state.records.push(created);
|
|
815
|
+
}
|
|
816
|
+
return json(200, { status: "success", responsedata: { dnsrecords: [{ id: "r1" }] } });
|
|
817
|
+
}
|
|
818
|
+
return json(200, { status: "success", responsedata: { dnsrecords: [{ id: "r1" }] } });
|
|
819
|
+
}
|
|
820
|
+
if (opts.provider === "namecheap") {
|
|
821
|
+
res.writeHead(200, { "content-type": "text/plain" });
|
|
822
|
+
res.end("good 1.2.3.4");
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
825
|
+
const rec = stdRec(body);
|
|
826
|
+
// ultradns: create path /zones/:z/rrsets/{TYPE}/{NAME} — extract from URL
|
|
827
|
+
if (opts.provider === "ultradns" && !rec.name) {
|
|
828
|
+
const m = url.pathname.match(/\/rrsets\/([^/]+)\/([^/]+)$/);
|
|
829
|
+
if (m) {
|
|
830
|
+
rec.type = rec.type || m[1] || "";
|
|
831
|
+
rec.name = (m[2] ?? "").replace(/\.$/, "");
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
// only store the record if we actually parsed a name (some providers
|
|
835
|
+
// post metadata-only or batch payloads that pass through here)
|
|
836
|
+
const created = { id: randomUUID(), type: rec.type, name: rec.name, value: rec.value, ttl: rec.ttl };
|
|
837
|
+
if (rec.name)
|
|
838
|
+
state.records.push(created);
|
|
839
|
+
const out = opts.provider === "dnsmadeeasy" ? { id: created.id, data: state.records.map(apiShape) }
|
|
840
|
+
: opts.provider === "constellix" ? { data: { id: created.id } }
|
|
841
|
+
: { id: created.id, record: apiShape(created) };
|
|
842
|
+
if (opts.provider === "cloudxns")
|
|
843
|
+
return json(200, { code: 1, data: { id: created.id } });
|
|
844
|
+
if (opts.provider === "infoblox")
|
|
845
|
+
return json(200, { _ref: created.id });
|
|
846
|
+
return json(200, out);
|
|
847
|
+
}
|
|
848
|
+
if (method === "PUT") {
|
|
849
|
+
const rec = stdRec(body);
|
|
850
|
+
// ultradns updates via PUT /rrsets/{TYPE}/{NAME} with body {ttl, rdata} —
|
|
851
|
+
// extract the real name/type from the URL (body has no name).
|
|
852
|
+
if (opts.provider === "ultradns" && !rec.name) {
|
|
853
|
+
const m = url.pathname.match(/\/rrsets\/([^/]+)\/([^/]+)$/);
|
|
854
|
+
if (m) {
|
|
855
|
+
rec.type = rec.type || m[1] || "";
|
|
856
|
+
rec.name = (m[2] ?? "").replace(/\.$/, "");
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
// devnomads PUT /zones/{zid}/rrsets/{NAME}/{TYPE}; misaka PUT /recordsets/{NAME}/{TYPE}
|
|
860
|
+
if (!rec.name && /\/(rrsets|recordsets)\/([^/]+)\/([^/]+)$/.test(url.pathname)) {
|
|
861
|
+
const m = url.pathname.match(/\/(?:rrsets|recordsets)\/([^/]+)\/([^/]+)$/);
|
|
862
|
+
if (m) {
|
|
863
|
+
rec.name = (m[1] ?? "").replace(/\.$/, "");
|
|
864
|
+
rec.type = rec.type || m[2] || "";
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
// azure PUT /subscriptions/.../dnsZones/{zone}/{TYPE}/{label} — name in the
|
|
868
|
+
// URL, value in {properties:{TXTRecords|ARecords|CNAMERecord}}.
|
|
869
|
+
if (opts.provider === "azure" && /\/dnsZones\/[^/]+\/([^/]+)\/([^/]+)/.test(url.pathname)) {
|
|
870
|
+
const m = url.pathname.match(/\/dnsZones\/[^/]+\/([^/]+)\/([^/]+)/);
|
|
871
|
+
if (m) {
|
|
872
|
+
rec.type = rec.type || m[1] || "";
|
|
873
|
+
rec.name = m[2] ?? "";
|
|
874
|
+
}
|
|
875
|
+
const props = (() => { if (body) {
|
|
876
|
+
try {
|
|
877
|
+
return JSON.parse(body);
|
|
878
|
+
}
|
|
879
|
+
catch {
|
|
880
|
+
return Object.fromEntries(new URLSearchParams(body));
|
|
881
|
+
}
|
|
882
|
+
} return {}; })();
|
|
883
|
+
const txt = props.TXTRecords?.[0]?.value?.[0];
|
|
884
|
+
const a = props.ARecords?.[0]?.ipv4Address;
|
|
885
|
+
const cname = props.CNAMERecord?.cname;
|
|
886
|
+
const ttl = props.TTL !== undefined ? Number(props.TTL) : undefined;
|
|
887
|
+
rec.value = String(txt ?? a ?? cname ?? rec.value ?? "");
|
|
888
|
+
rec.ttl = ttl !== undefined && !isNaN(ttl) ? ttl : rec.ttl;
|
|
889
|
+
}
|
|
890
|
+
const existing = state.records.find((r) => r.id === trailing || r.name === rec.name);
|
|
891
|
+
if (!existing && rec.name) {
|
|
892
|
+
const created = { id: randomUUID(), type: rec.type, name: rec.name, value: rec.value, ttl: rec.ttl };
|
|
893
|
+
state.records.push(created);
|
|
894
|
+
return json(200, opts.provider === "namecheap" ? "good 1.2.3.4" : apiShape(created));
|
|
895
|
+
}
|
|
896
|
+
if (existing) {
|
|
897
|
+
if (rec.type)
|
|
898
|
+
existing.type = rec.type;
|
|
899
|
+
if (rec.name)
|
|
900
|
+
existing.name = rec.name;
|
|
901
|
+
if (rec.value)
|
|
902
|
+
existing.value = rec.value;
|
|
903
|
+
if (rec.ttl !== undefined)
|
|
904
|
+
existing.ttl = rec.ttl;
|
|
905
|
+
return json(200, opts.provider === "namecheap" ? "good 1.2.3.4" : opts.provider === "cloudxns" ? { code: 1, data: {} } : apiShape(existing));
|
|
906
|
+
}
|
|
907
|
+
return json(404, { error: "not found" });
|
|
908
|
+
}
|
|
909
|
+
if (method === "PATCH") {
|
|
910
|
+
// rcodezero: PATCH /zones/{zid}/rrsets {name,type,records:[{content}],ttl}
|
|
911
|
+
// powerdns: PATCH /zones/{zone}. {rrsets:[{name,type,ttl,changetype,records}]}
|
|
912
|
+
const srcBody = (() => { if (body) {
|
|
913
|
+
try {
|
|
914
|
+
return JSON.parse(body);
|
|
915
|
+
}
|
|
916
|
+
catch {
|
|
917
|
+
return Object.fromEntries(new URLSearchParams(body));
|
|
918
|
+
}
|
|
919
|
+
} return {}; })();
|
|
920
|
+
// OCI: PATCH /zones/{zone}/records/{name} with {items:[{domain,rtype,rdata,ttl}]}
|
|
921
|
+
if (opts.provider === "oci") {
|
|
922
|
+
const items = srcBody.items ?? [];
|
|
923
|
+
const pathName = url.pathname.split("/").pop() ?? "";
|
|
924
|
+
for (const it of items) {
|
|
925
|
+
const rec = stdRec(it);
|
|
926
|
+
const nm = rec.name || pathName.replace(/\.$/, "");
|
|
927
|
+
if (rec.name)
|
|
928
|
+
state.records.push({ id: randomUUID(), type: rec.type, name: nm, value: rec.value, ttl: rec.ttl });
|
|
929
|
+
else {
|
|
930
|
+
const ex = state.records.find((r) => r.name === nm);
|
|
931
|
+
if (ex && rec.value)
|
|
932
|
+
ex.value = rec.value;
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
return json(200, {});
|
|
936
|
+
}
|
|
937
|
+
const src = srcBody.rrsets?.[0] ?? srcBody;
|
|
938
|
+
const rec = stdRec(src);
|
|
939
|
+
// powerdns wraps the value in records[0].content
|
|
940
|
+
if (rec.value === "") {
|
|
941
|
+
const inner = src.records?.[0];
|
|
942
|
+
if (inner)
|
|
943
|
+
rec.value = String(inner.content ?? inner.value ?? "");
|
|
944
|
+
}
|
|
945
|
+
const ct = String(src.changetype ?? "");
|
|
946
|
+
// powerdns DELETE changetype
|
|
947
|
+
if (ct === "DELETE")
|
|
948
|
+
state.records = state.records.filter((r) => !(r.name === rec.name && (!rec.type || r.type === rec.type)));
|
|
949
|
+
else {
|
|
950
|
+
const existing = state.records.find((r) => r.name === rec.name && (!rec.type || r.type === rec.type));
|
|
951
|
+
if (existing) {
|
|
952
|
+
existing.value = rec.value;
|
|
953
|
+
if (rec.ttl !== undefined)
|
|
954
|
+
existing.ttl = rec.ttl;
|
|
955
|
+
}
|
|
956
|
+
else if (rec.name)
|
|
957
|
+
state.records.push({ id: randomUUID(), type: rec.type, name: rec.name, value: rec.value, ttl: rec.ttl });
|
|
958
|
+
}
|
|
959
|
+
return json(200, {});
|
|
960
|
+
}
|
|
961
|
+
if (method === "DELETE") {
|
|
962
|
+
const delRec = stdRec(body);
|
|
963
|
+
const norm = (s) => s.replace(/\.$/, "");
|
|
964
|
+
// hover deletes by body {id} (no path segment / body name) — parse the id.
|
|
965
|
+
const delBody = (() => { if (body) {
|
|
966
|
+
try {
|
|
967
|
+
return JSON.parse(body);
|
|
968
|
+
}
|
|
969
|
+
catch {
|
|
970
|
+
return Object.fromEntries(new URLSearchParams(body));
|
|
971
|
+
}
|
|
972
|
+
} return {}; })();
|
|
973
|
+
const delId = String(delBody.id ?? "");
|
|
974
|
+
if (opts.provider === "hover" && delId) {
|
|
975
|
+
const idxH = state.records.findIndex((r) => r.id === delId);
|
|
976
|
+
if (idxH >= 0)
|
|
977
|
+
state.records.splice(idxH, 1);
|
|
978
|
+
return json(200, {});
|
|
979
|
+
}
|
|
980
|
+
// collect candidate record identifiers from the path: trailing segment,
|
|
981
|
+
// the segment before it (cloudxns /id/did), and the NAME after
|
|
982
|
+
// /rrsets/{TYPE}/{NAME} (ultradns).
|
|
983
|
+
const segs = url.pathname.split("/").filter(Boolean);
|
|
984
|
+
const rrsetsMatch = url.pathname.match(/\/rrsets\/[^/]+\/([^/]+)$/);
|
|
985
|
+
const candidates = [trailing, segs[segs.length - 2], rrsetsMatch?.[1] ?? "", delRec.name ?? ""]
|
|
986
|
+
.filter((s) => Boolean(s)).map(norm);
|
|
987
|
+
const idx = state.records.findIndex((r) => {
|
|
988
|
+
if (r.id === trailing || candidates.includes(norm(r.id ?? "")))
|
|
989
|
+
return true;
|
|
990
|
+
if (candidates.includes(norm(r.name ?? "")))
|
|
991
|
+
return true;
|
|
992
|
+
if (delRec.name && norm(r.name ?? "") === norm(delRec.name) && (!delRec.type || r.type === delRec.type))
|
|
993
|
+
return true;
|
|
994
|
+
return false;
|
|
995
|
+
});
|
|
996
|
+
if (idx < 0)
|
|
997
|
+
return json(404, { error: "not found" });
|
|
998
|
+
state.records.splice(idx, 1);
|
|
999
|
+
if (opts.provider === "cloudxns")
|
|
1000
|
+
return json(200, { code: 1, data: {} });
|
|
1001
|
+
if (opts.provider === "namecheap")
|
|
1002
|
+
return json(200, "good 1.2.3.4");
|
|
1003
|
+
return json(200, { ok: true });
|
|
1004
|
+
}
|
|
1005
|
+
json(405, { error: "method not allowed" });
|
|
1006
|
+
});
|
|
1007
|
+
});
|
|
1008
|
+
await new Promise((resolve) => server.listen(opts.port ?? 0, "127.0.0.1", resolve));
|
|
1009
|
+
const addr = server.address();
|
|
1010
|
+
const port = typeof addr === "object" && addr ? addr.port : 0;
|
|
1011
|
+
return {
|
|
1012
|
+
url: `http://127.0.0.1:${port}`,
|
|
1013
|
+
state,
|
|
1014
|
+
stop: () => new Promise((resolve) => server.close(() => resolve())),
|
|
1015
|
+
};
|
|
1016
|
+
}
|
|
1017
|
+
export { defaultFetchLike };
|