type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Upload Certificate
* Upload your own certificate you want Cloudflare to use for edge-to-origin communication to override the shared certificate. Please note that it is important to keep only one certificate active. Also, make sure to enable zone-level authenticated origin pulls by making a PUT call to settings endpoint to see the uploaded certificate in use.
*/
export async function main(
auth: Cloudflare,
zone_identifier: string,
body: { certificate: string; private_key: string; [k: string]: unknown }
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/zones/${zone_identifier}/origin_tls_client_auth`
);
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;
};
/**
* Upload Certificate
* Upload your own certificate you want Cloudflare to use for edge-to-origin communication to override the shared certificate. Please note that it is important to keep only one certificate active. Also, make sure to enable zone-level authenticated origin pulls by making a PUT call to settings endpoint to see the uploaded certificate in use.
*/
export async function main(
auth: Cloudflare,
zone_identifier: string,
body: { certificate: string; private_key: string; [k: string]: unknown }
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/zones/${zone_identifier}/origin_tls_client_auth`
);
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