//native
type Digitalocean = {
token: string;
};
/**
* Create a New CDN Endpoint
* To create a new CDN endpoint, send a POST request to `/v2/cdn/endpoints`. The
origin attribute must be set to the fully qualified domain name (FQDN) of a
DigitalOcean Space. Optionally, the TTL may be configured by setting the `ttl`
attribute.
A custom subdomain may be configured by specifying the `custom_domain` and
`certificate_id` attributes.
*/
export async function main(
auth: Digitalocean,
body: {
id?: string;
origin: string;
endpoint?: string;
ttl?: 60 | 600 | 3600 | 86400 | 604800;
certificate_id?: string;
custom_domain?: string;
created_at?: string;
},
) {
const url = new URL(`https://api.digitalocean.com/v2/cdn/endpoints`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 536 days ago