List configured pools.
1
type Cloudflare = {
2
token: string;
3
email: string;
4
key: string;
5
};
6
/**
7
* List Pools
8
* List configured pools.
9
*/
10
export async function main(auth: Cloudflare, monitor: string | undefined) {
11
const url = new URL(
12
`https://api.cloudflare.com/client/v4/user/load_balancers/pools`
13
);
14
for (const [k, v] of [["monitor", monitor]]) {
15
if (v !== undefined && v !== "") {
16
url.searchParams.append(k, v);
17
}
18
19
const response = await fetch(url, {
20
method: "GET",
21
headers: {
22
"X-AUTH-EMAIL": auth.email,
23
"X-AUTH-KEY": auth.key,
24
Authorization: "Bearer " + auth.token,
25
},
26
body: undefined,
27
});
28
if (!response.ok) {
29
const text = await response.text();
30
throw new Error(`${response.status} ${text}`);
31
32
return await response.json();
33
34