(account, headers, project, customDomain)
| 183 | } |
| 184 | |
| 185 | async function addPagesDomain(account, headers, project, customDomain) { |
| 186 | if (await projectHasPagesDomain(account, headers, project, customDomain)) { |
| 187 | console.log(`Pages custom domain ready: ${customDomain}`); |
| 188 | return; |
| 189 | } |
| 190 | |
| 191 | const postDomain = () => |
| 192 | cf( |
| 193 | `${CF_API}/accounts/${account}/pages/projects/${project}/domains`, |
| 194 | headers, |
| 195 | { |
| 196 | method: "POST", |
| 197 | body: JSON.stringify({ name: customDomain }), |
| 198 | }, |
| 199 | ); |
| 200 | |
| 201 | let { ok, json } = await postDomain(); |
| 202 | if (ok || hasCode(json, 8000007)) { |
| 203 | console.log(`Pages custom domain ready: ${customDomain}`); |
| 204 | return; |
| 205 | } |
| 206 | |
| 207 | if (hasCode(json, 8000018)) { |
| 208 | console.log(`${customDomain} claimed elsewhere; reclaiming`); |
| 209 | await detachPagesDomain(account, headers, customDomain); |
| 210 | ({ ok, json } = await postDomain()); |
| 211 | if (ok || hasCode(json, 8000007)) { |
| 212 | console.log(`Pages custom domain reclaimed: ${customDomain}`); |
| 213 | return; |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | throw new Error( |
| 218 | `Add Pages domain ${customDomain} failed: ${JSON.stringify(json)}`, |
| 219 | ); |
| 220 | } |
| 221 | |
| 222 | async function upsertCname(zoneId, headers, name, target) { |
| 223 | const { ok, json } = await cf( |
no test coverage detected