1 | |
2 | type Linode = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create a config |
7 | * Creates a NodeBalancer configuration, which allows the NodeBalancer to accept traffic on a new port. |
8 | */ |
9 | export async function main( |
10 | auth: Linode, |
11 | apiVersion: "v4" | "v4beta", |
12 | nodeBalancerId: string, |
13 | body: |
14 | | { |
15 | algorithm?: "roundrobin" | "leastconn" | "source"; |
16 | check?: "none" | "connection" | "http" | "http_body"; |
17 | check_attempts?: number; |
18 | check_body?: string; |
19 | check_interval?: number; |
20 | check_passive?: false | true; |
21 | check_path?: string; |
22 | check_timeout?: number; |
23 | cipher_suite?: string; |
24 | id?: number; |
25 | nodebalancer_id?: number; |
26 | nodes_status?: { down?: number; up?: number }; |
27 | port?: number; |
28 | protocol?: "tcp"; |
29 | proxy_protocol?: "none" | "v1" | "v2"; |
30 | ssl_cert?: string; |
31 | ssl_commonname?: string; |
32 | ssl_fingerprint?: string; |
33 | ssl_key?: string; |
34 | stickiness?: "none" | "table"; |
35 | } |
36 | | { |
37 | algorithm?: "roundrobin" | "leastconn" | "source"; |
38 | check?: "none" | "connection" | "http" | "http_body"; |
39 | check_attempts?: number; |
40 | check_body?: string; |
41 | check_interval?: number; |
42 | check_passive?: false | true; |
43 | check_path?: string; |
44 | check_timeout?: number; |
45 | cipher_suite?: string; |
46 | id?: number; |
47 | nodebalancer_id?: number; |
48 | nodes_status?: { down?: number; up?: number }; |
49 | port?: number; |
50 | protocol?: "http"; |
51 | proxy_protocol?: string; |
52 | ssl_cert?: string; |
53 | ssl_commonname?: string; |
54 | ssl_fingerprint?: string; |
55 | ssl_key?: string; |
56 | stickiness?: "none" | "table" | "http_cookie"; |
57 | } |
58 | | { |
59 | algorithm?: "roundrobin" | "leastconn" | "source"; |
60 | check?: "none" | "connection" | "http" | "http_body"; |
61 | check_attempts?: number; |
62 | check_body?: string; |
63 | check_interval?: number; |
64 | check_passive?: false | true; |
65 | check_path?: string; |
66 | check_timeout?: number; |
67 | cipher_suite?: "recommended" | "legacy"; |
68 | id?: number; |
69 | nodebalancer_id?: number; |
70 | nodes_status?: { down?: number; up?: number }; |
71 | port?: number; |
72 | protocol?: "https"; |
73 | proxy_protocol?: string; |
74 | ssl_cert?: string; |
75 | ssl_commonname?: string; |
76 | ssl_fingerprint?: string; |
77 | ssl_key?: string; |
78 | stickiness?: "none" | "table" | "http_cookie"; |
79 | }, |
80 | ) { |
81 | const url = new URL( |
82 | `https://api.linode.com/${apiVersion}/nodebalancers/${nodeBalancerId}/configs`, |
83 | ); |
84 |
|
85 | const response = await fetch(url, { |
86 | method: "POST", |
87 | headers: { |
88 | "Content-Type": "application/json", |
89 | Authorization: "Bearer " + auth.token, |
90 | }, |
91 | body: JSON.stringify(body), |
92 | }); |
93 | if (!response.ok) { |
94 | const text = await response.text(); |
95 | throw new Error(`${response.status} ${text}`); |
96 | } |
97 | return await response.json(); |
98 | } |
99 |
|