1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { fetch } from "https://esm.town/v/std/fetch";
export const glifJson = async (req: Reqeust) => {
const searchParams = new URL(req.url).searchParams;
const id = searchParams.get("id");
const url = `https://glif.app/api/glifs?id=${id}`;
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const json = await response.json();
const data = searchParams.get("data") ? json[0]?.data : json[0];
if (data) {
return Response.json(data);
}
else {
throw new Error("bad JSON response");
}
}
catch (error) {
return Response.json({ error: error.message });
}
};