type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Create Custom Hostname
* Add a new custom hostname and request that an SSL certificate be issued for it.
*/
export async function main(
auth: Cloudflare,
zone_identifier: string,
body: {
custom_metadata?: { key?: string; [k: string]: unknown };
hostname: string;
ssl: {
bundle_method?: "ubiquitous" | "optimal" | "force";
certificate_authority?: "digicert" | "google" | "lets_encrypt";
custom_certificate?: string;
custom_key?: string;
method?: "http" | "txt" | "email";
settings?: {
ciphers?: string[];
early_hints?: "on" | "off";
http2?: "on" | "off";
min_tls_version?: "1.0" | "1.1" | "1.2" | "1.3";
tls_1_3?: "on" | "off";
[k: string]: unknown;
};
type?: "dv";
wildcard?: boolean;
[k: string]: unknown;
};
[k: string]: unknown;
}
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/zones/${zone_identifier}/custom_hostnames`
);
const response = await fetch(url, {
method: "POST",
headers: {
"X-AUTH-EMAIL": auth.email,
"X-AUTH-KEY": auth.key,
"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 383 days ago
type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Create Custom Hostname
* Add a new custom hostname and request that an SSL certificate be issued for it.
*/
export async function main(
auth: Cloudflare,
zone_identifier: string,
body: {
custom_metadata?: { key?: string; [k: string]: unknown };
hostname: string;
ssl: {
bundle_method?: "ubiquitous" | "optimal" | "force";
certificate_authority?: "digicert" | "google" | "lets_encrypt";
custom_certificate?: string;
custom_key?: string;
method?: "http" | "txt" | "email";
settings?: {
ciphers?: string[];
early_hints?: "on" | "off";
http2?: "on" | "off";
min_tls_version?: "1.0" | "1.1" | "1.2" | "1.3";
tls_1_3?: "on" | "off";
[k: string]: unknown;
};
type?: "dv";
wildcard?: boolean;
[k: string]: unknown;
};
[k: string]: unknown;
}
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/zones/${zone_identifier}/custom_hostnames`
);
const response = await fetch(url, {
method: "POST",
headers: {
"X-AUTH-EMAIL": auth.email,
"X-AUTH-KEY": auth.key,
"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 920 days ago