type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Update Spectrum application configuration using a name for the origin
* Updates a previously existing application's configuration that uses a name for the origin.
*/
export async function main(
auth: Cloudflare,
app_id: string,
zone: string,
body: {
argo_smart_routing?: boolean;
dns: { name?: string; type?: "CNAME" | "ADDRESS"; [k: string]: unknown };
edge_ips?:
| {
connectivity?: "all" | "ipv4" | "ipv6";
type?: "dynamic";
[k: string]: unknown;
}
| { ips?: string[]; type?: "static"; [k: string]: unknown };
ip_firewall?: boolean;
origin_dns: {
name?: string;
ttl?: number;
type?: "" | "A" | "AAAA" | "SRV";
[k: string]: unknown;
};
origin_port: number | string;
protocol: string;
proxy_protocol?: "off" | "v1" | "v2" | "simple";
tls?: "off" | "flexible" | "full" | "strict";
traffic_type?: "direct" | "http" | "https";
[k: string]: unknown;
}
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/zones/${zone}/spectrum/apps/${app_id}`
);
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 Spectrum application configuration using a name for the origin
* Updates a previously existing application's configuration that uses a name for the origin.
*/
export async function main(
auth: Cloudflare,
app_id: string,
zone: string,
body: {
argo_smart_routing?: boolean;
dns: { name?: string; type?: "CNAME" | "ADDRESS"; [k: string]: unknown };
edge_ips?:
| {
connectivity?: "all" | "ipv4" | "ipv6";
type?: "dynamic";
[k: string]: unknown;
}
| { ips?: string[]; type?: "static"; [k: string]: unknown };
ip_firewall?: boolean;
origin_dns: {
name?: string;
ttl?: number;
type?: "" | "A" | "AAAA" | "SRV";
[k: string]: unknown;
};
origin_port: number | string;
protocol: string;
proxy_protocol?: "off" | "v1" | "v2" | "simple";
tls?: "off" | "flexible" | "full" | "strict";
traffic_type?: "direct" | "http" | "https";
[k: string]: unknown;
}
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/zones/${zone}/spectrum/apps/${app_id}`
);
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