MCPcopy Create free account
hub / github.com/pollinations/pollinations / addPagesDomain

Function addPagesDomain

apps/_scripts/deploy-app.js:185–220  ·  view source on GitHub ↗
(account, headers, project, customDomain)

Source from the content-addressed store, hash-verified

183}
184
185async 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
222async function upsertCname(zoneId, headers, name, target) {
223 const { ok, json } = await cf(

Callers 1

runOriginFunction · 0.85

Calls 6

projectHasPagesDomainFunction · 0.85
postDomainFunction · 0.85
hasCodeFunction · 0.85
detachPagesDomainFunction · 0.85
logMethod · 0.80
stringifyMethod · 0.80

Tested by

no test coverage detected