Put configuration

Adds or updates the configuration for a remotely-managed tunnel.

Script cloudflare Verified

by hugo697 ยท 11/16/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 383 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * Put configuration
8
 * Adds or updates the configuration for a remotely-managed tunnel.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  tunnel_id: string,
13
  account_identifier: string,
14
  body: {
15
    config?: {
16
      ingress?: {
17
        hostname: string;
18
        originRequest?: {
19
          access?: {
20
            audTag: string[];
21
            required?: boolean;
22
            teamName: string;
23
            [k: string]: unknown;
24
          };
25
          caPool?: string;
26
          connectTimeout?: number;
27
          disableChunkedEncoding?: boolean;
28
          http2Origin?: boolean;
29
          httpHostHeader?: string;
30
          keepAliveConnections?: number;
31
          keepAliveTimeout?: number;
32
          noHappyEyeballs?: boolean;
33
          noTLSVerify?: boolean;
34
          originServerName?: string;
35
          proxyType?: string;
36
          tcpKeepAlive?: number;
37
          tlsTimeout?: number;
38
          [k: string]: unknown;
39
        };
40
        path?: string;
41
        service: string;
42
        [k: string]: unknown;
43
      }[];
44
      originRequest?: {
45
        access?: {
46
          audTag: string[];
47
          required?: boolean;
48
          teamName: string;
49
          [k: string]: unknown;
50
        };
51
        caPool?: string;
52
        connectTimeout?: number;
53
        disableChunkedEncoding?: boolean;
54
        http2Origin?: boolean;
55
        httpHostHeader?: string;
56
        keepAliveConnections?: number;
57
        keepAliveTimeout?: number;
58
        noHappyEyeballs?: boolean;
59
        noTLSVerify?: boolean;
60
        originServerName?: string;
61
        proxyType?: string;
62
        tcpKeepAlive?: number;
63
        tlsTimeout?: number;
64
        [k: string]: unknown;
65
      };
66
      "warp-routing"?: { enabled?: boolean; [k: string]: unknown };
67
      [k: string]: unknown;
68
    };
69
    [k: string]: unknown;
70
  }
71
) {
72
  const url = new URL(
73
    `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/cfd_tunnel/${tunnel_id}/configurations`
74
  );
75

76
  const response = await fetch(url, {
77
    method: "PUT",
78
    headers: {
79
      "X-AUTH-EMAIL": auth.email,
80
      "X-AUTH-KEY": auth.key,
81
      "Content-Type": "application/json",
82
      Authorization: "Bearer " + auth.token,
83
    },
84
    body: JSON.stringify(body),
85
  });
86
  if (!response.ok) {
87
    const text = await response.text();
88
    throw new Error(`${response.status} ${text}`);
89
  }
90
  return await response.json();
91
}
92