type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Start page test
* Starts a test for a specific webpage, in a specific region.
*/
export async function main(
auth: Cloudflare,
zone_identifier: string,
url: string,
body: {
region?:
| "asia-east1"
| "asia-northeast1"
| "asia-northeast2"
| "asia-south1"
| "asia-southeast1"
| "australia-southeast1"
| "europe-north1"
| "europe-southwest1"
| "europe-west1"
| "europe-west2"
| "europe-west3"
| "europe-west4"
| "europe-west8"
| "europe-west9"
| "me-west1"
| "southamerica-east1"
| "us-central1"
| "us-east1"
| "us-east4"
| "us-south1"
| "us-west1";
[k: string]: unknown;
}
) {
const url_ = new URL(
`https://api.cloudflare.com/client/v4/zones/${zone_identifier}/speed_api/pages/${url}/tests`
);
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;
};
/**
* Start page test
* Starts a test for a specific webpage, in a specific region.
*/
export async function main(
auth: Cloudflare,
zone_identifier: string,
url: string,
body: {
region?:
| "asia-east1"
| "asia-northeast1"
| "asia-northeast2"
| "asia-south1"
| "asia-southeast1"
| "australia-southeast1"
| "europe-north1"
| "europe-southwest1"
| "europe-west1"
| "europe-west2"
| "europe-west3"
| "europe-west4"
| "europe-west8"
| "europe-west9"
| "me-west1"
| "southamerica-east1"
| "us-central1"
| "us-east1"
| "us-east4"
| "us-south1"
| "us-west1";
[k: string]: unknown;
}
) {
const url_ = new URL(
`https://api.cloudflare.com/client/v4/zones/${zone_identifier}/speed_api/pages/${url}/tests`
);
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