Openstatus
www.openstatus.dev
1// List of all Cloudflare data center taken by https://www.feitsui.com/en/article/26
2import { regions } from "../regions/cloudflare";
3import type { ParserReturn, Region } from "../types";
4
5export function parseCfRay(header: string): ParserReturn<Region> {
6 const regex = /\b([A-Z]{3})\b/g;
7 const arr = header.match(regex);
8
9 if (!arr || !Array.isArray(arr) || arr.length === 0) {
10 return { status: "failed", error: new Error("Couldn't parse the header.") };
11 }
12
13 const region = regions[arr[0]];
14 if (region) return { status: "success", data: region };
15
16 return {
17 status: "failed",
18 error: new Error(
19 `It seems like the data center '${arr[0]}' (iata) is not listed.`,
20 ),
21 };
22}