//native
type Linode = {
token: string;
};
/**
* Create a config
* Creates a NodeBalancer configuration, which allows the NodeBalancer to accept traffic on a new port.
*/
export async function main(
auth: Linode,
apiVersion: "v4" | "v4beta",
nodeBalancerId: string,
body:
| {
algorithm?: "roundrobin" | "leastconn" | "source";
check?: "none" | "connection" | "http" | "http_body";
check_attempts?: number;
check_body?: string;
check_interval?: number;
check_passive?: false | true;
check_path?: string;
check_timeout?: number;
cipher_suite?: string;
id?: number;
nodebalancer_id?: number;
nodes_status?: { down?: number; up?: number };
port?: number;
protocol?: "tcp";
proxy_protocol?: "none" | "v1" | "v2";
ssl_cert?: string;
ssl_commonname?: string;
ssl_fingerprint?: string;
ssl_key?: string;
stickiness?: "none" | "table";
}
| {
algorithm?: "roundrobin" | "leastconn" | "source";
check?: "none" | "connection" | "http" | "http_body";
check_attempts?: number;
check_body?: string;
check_interval?: number;
check_passive?: false | true;
check_path?: string;
check_timeout?: number;
cipher_suite?: string;
id?: number;
nodebalancer_id?: number;
nodes_status?: { down?: number; up?: number };
port?: number;
protocol?: "http";
proxy_protocol?: string;
ssl_cert?: string;
ssl_commonname?: string;
ssl_fingerprint?: string;
ssl_key?: string;
stickiness?: "none" | "table" | "http_cookie";
}
| {
algorithm?: "roundrobin" | "leastconn" | "source";
check?: "none" | "connection" | "http" | "http_body";
check_attempts?: number;
check_body?: string;
check_interval?: number;
check_passive?: false | true;
check_path?: string;
check_timeout?: number;
cipher_suite?: "recommended" | "legacy";
id?: number;
nodebalancer_id?: number;
nodes_status?: { down?: number; up?: number };
port?: number;
protocol?: "https";
proxy_protocol?: string;
ssl_cert?: string;
ssl_commonname?: string;
ssl_fingerprint?: string;
ssl_key?: string;
stickiness?: "none" | "table" | "http_cookie";
},
) {
const url = new URL(
`https://api.linode.com/${apiVersion}/nodebalancers/${nodeBalancerId}/configs`,
);
const response = await fetch(url, {
method: "POST",
headers: {
"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 235 days ago