0

Update a config

by
Published Oct 17, 2025

Updates the configuration for a single port on a NodeBalancer.

Script linode Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Linode = {
3
  token: string;
4
};
5
/**
6
 * Update a config
7
 * Updates the configuration for a single port on a NodeBalancer.
8
 */
9
export async function main(
10
  auth: Linode,
11
  apiVersion: "v4" | "v4beta",
12
  nodeBalancerId: string,
13
  configId: string,
14
  body:
15
    | {
16
        algorithm?: "roundrobin" | "leastconn" | "source";
17
        check?: "none" | "connection" | "http" | "http_body";
18
        check_attempts?: number;
19
        check_body?: string;
20
        check_interval?: number;
21
        check_passive?: false | true;
22
        check_path?: string;
23
        check_timeout?: number;
24
        cipher_suite?: string;
25
        id?: number;
26
        nodebalancer_id?: number;
27
        nodes_status?: { down?: number; up?: number };
28
        port?: number;
29
        protocol?: "tcp";
30
        proxy_protocol?: "none" | "v1" | "v2";
31
        ssl_cert?: string;
32
        ssl_commonname?: string;
33
        ssl_fingerprint?: string;
34
        ssl_key?: string;
35
        stickiness?: "none" | "table";
36
      }
37
    | {
38
        algorithm?: "roundrobin" | "leastconn" | "source";
39
        check?: "none" | "connection" | "http" | "http_body";
40
        check_attempts?: number;
41
        check_body?: string;
42
        check_interval?: number;
43
        check_passive?: false | true;
44
        check_path?: string;
45
        check_timeout?: number;
46
        cipher_suite?: string;
47
        id?: number;
48
        nodebalancer_id?: number;
49
        nodes_status?: { down?: number; up?: number };
50
        port?: number;
51
        protocol?: "http";
52
        proxy_protocol?: string;
53
        ssl_cert?: string;
54
        ssl_commonname?: string;
55
        ssl_fingerprint?: string;
56
        ssl_key?: string;
57
        stickiness?: "none" | "table" | "http_cookie";
58
      }
59
    | {
60
        algorithm?: "roundrobin" | "leastconn" | "source";
61
        check?: "none" | "connection" | "http" | "http_body";
62
        check_attempts?: number;
63
        check_body?: string;
64
        check_interval?: number;
65
        check_passive?: false | true;
66
        check_path?: string;
67
        check_timeout?: number;
68
        cipher_suite?: "recommended" | "legacy";
69
        id?: number;
70
        nodebalancer_id?: number;
71
        nodes_status?: { down?: number; up?: number };
72
        port?: number;
73
        protocol?: "https";
74
        proxy_protocol?: string;
75
        ssl_cert?: string;
76
        ssl_commonname?: string;
77
        ssl_fingerprint?: string;
78
        ssl_key?: string;
79
        stickiness?: "none" | "table" | "http_cookie";
80
      },
81
) {
82
  const url = new URL(
83
    `https://api.linode.com/${apiVersion}/nodebalancers/${nodeBalancerId}/configs/${configId}`,
84
  );
85

86
  const response = await fetch(url, {
87
    method: "PUT",
88
    headers: {
89
      "Content-Type": "application/json",
90
      Authorization: "Bearer " + auth.token,
91
    },
92
    body: JSON.stringify(body),
93
  });
94
  if (!response.ok) {
95
    const text = await response.text();
96
    throw new Error(`${response.status} ${text}`);
97
  }
98
  return await response.json();
99
}
100