Change Server Side Exclude setting

If there is sensitive content on your website that you want visible to real visitors, but that you want to hide from suspicious visitors, all you have to do is wrap the content with Cloudflare SSE tags.

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 Server Side Exclude setting
8
 * If there is sensitive content on your website that you want visible to real visitors, but that you want to hide from suspicious visitors, all you have to do is wrap the content with Cloudflare SSE tags.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  zone_identifier: string,
13
  body: { value: "on" | "off"; [k: string]: unknown }
14
) {
15
  const url = new URL(
16
    `https://api.cloudflare.com/client/v4/zones/${zone_identifier}/settings/server_side_exclude`
17
  );
18

19
  const response = await fetch(url, {
20
    method: "PATCH",
21
    headers: {
22
      "X-AUTH-EMAIL": auth.email,
23
      "X-AUTH-KEY": auth.key,
24
      "Content-Type": "application/json",
25
      Authorization: "Bearer " + auth.token,
26
    },
27
    body: JSON.stringify(body),
28
  });
29
  if (!response.ok) {
30
    const text = await response.text();
31
    throw new Error(`${response.status} ${text}`);
32
  }
33
  return await response.json();
34
}
35