Change Proxy Read Timeout setting

Maximum time between two read operations from origin.

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
 * Change Proxy Read Timeout setting
8
 * Maximum time between two read operations from origin.
9

10
 */
11
export async function main(
12
  auth: Cloudflare,
13
  zone_identifier: string,
14
  body: {
15
    value: {
16
      editable?: true | false;
17
      id: string;
18
      modified_on?: string;
19
      value: { [k: string]: unknown };
20
      [k: string]: unknown;
21
    } & { id?: "proxy_read_timeout"; value?: number; [k: string]: unknown };
22
    [k: string]: unknown;
23
  }
24
) {
25
  const url = new URL(
26
    `https://api.cloudflare.com/client/v4/zones/${zone_identifier}/settings/proxy_read_timeout`
27
  );
28

29
  const response = await fetch(url, {
30
    method: "PATCH",
31
    headers: {
32
      "X-AUTH-EMAIL": auth.email,
33
      "X-AUTH-KEY": auth.key,
34
      "Content-Type": "application/json",
35
      Authorization: "Bearer " + auth.token,
36
    },
37
    body: JSON.stringify(body),
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.json();
44
}
45