(zoneId, headers, name)
| 282 | } |
| 283 | |
| 284 | async function deleteCname(zoneId, headers, name) { |
| 285 | const { ok, json } = await cf( |
| 286 | `${CF_API}/zones/${zoneId}/dns_records?type=CNAME&name=${name}`, |
| 287 | headers, |
| 288 | ); |
| 289 | if (!ok) |
| 290 | throw new Error(`DNS list ${name} failed: ${JSON.stringify(json)}`); |
| 291 | |
| 292 | const record = json.result?.[0]; |
| 293 | if (!record) return; |
| 294 | |
| 295 | const { ok: deleteOk, json: deleted } = await cf( |
| 296 | `${CF_API}/zones/${zoneId}/dns_records/${record.id}`, |
| 297 | headers, |
| 298 | { method: "DELETE" }, |
| 299 | ); |
| 300 | if (!deleteOk) { |
| 301 | throw new Error( |
| 302 | `Delete CNAME ${name} failed: ${JSON.stringify(deleted)}`, |
| 303 | ); |
| 304 | } |
| 305 | console.log(`Removed old CNAME ${name}`); |
| 306 | } |
| 307 | |
| 308 | async function attachWorkerDomain(account, headers, hostname, zoneId) { |
| 309 | const { ok, json } = await cf( |
no test coverage detected