//native
type Linode = {
token: string;
};
/**
* Create a node
* Creates a NodeBalancer node, a backend that can accept traffic for this NodeBalancer Config.
*/
export async function main(
auth: Linode,
apiVersion: "v4" | "v4beta",
nodeBalancerId: string,
configId: string,
body: {
address?: string;
config_id?: number;
id?: number;
label?: string;
mode?: "accept" | "reject" | "drain" | "backup";
nodebalancer_id?: number;
status?: "unknown" | "UP" | "DOWN";
weight?: number;
},
) {
const url = new URL(
`https://api.linode.com/${apiVersion}/nodebalancers/${nodeBalancerId}/configs/${configId}/nodes`,
);
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