0
Create Railgun
One script reply has been approved by the moderators Verified
Created by hugo697 156 days ago Viewed 4174 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 156 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * Create Railgun
8
 *
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  body: { name: string; [k: string]: unknown }
13
) {
14
  const url = new URL(`https://api.cloudflare.com/client/v4/railguns`);
15

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