type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Update Many Routes
* Update multiple Magic static routes. Use `?validate_only=true` as an optional query parameter to run validation only without persisting changes. Only fields for a route that need to be changed need be provided.
*/
export async function main(
auth: Cloudflare,
account_identifier: string,
body: {
routes: ({ id: string; [k: string]: unknown } & {
description?: string;
nexthop: string;
prefix: string;
priority: number;
scope?: {
colo_names?: string[];
colo_regions?: string[];
[k: string]: unknown;
};
weight?: number;
[k: string]: unknown;
})[];
[k: string]: unknown;
}
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/accounts/${account_identifier}/magic/routes`
);
const response = await fetch(url, {
method: "PUT",
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;
};
/**
* Update Many Routes
* Update multiple Magic static routes. Use `?validate_only=true` as an optional query parameter to run validation only without persisting changes. Only fields for a route that need to be changed need be provided.
*/
export async function main(
auth: Cloudflare,
account_identifier: string,
body: {
routes: ({ id: string; [k: string]: unknown } & {
description?: string;
nexthop: string;
prefix: string;
priority: number;
scope?: {
colo_names?: string[];
colo_regions?: string[];
[k: string]: unknown;
};
weight?: number;
[k: string]: unknown;
})[];
[k: string]: unknown;
}
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/accounts/${account_identifier}/magic/routes`
);
const response = await fetch(url, {
method: "PUT",
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