-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgateway_github.ts
33 lines (27 loc) · 1.09 KB
/
gateway_github.ts
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
26
27
28
29
30
31
32
33
import type { HonoContext } from "../types";
import { OpenAPIHono } from "@hono/zod-openapi";
import { cache } from "hono/cache";
import { createError } from "../utils";
import { GITHUB_EMOJIS_ROUTE } from "./gateway_github.openapi";
export const GATEWAY_GITHUB_ROUTER = new OpenAPIHono<HonoContext>().basePath("/api/gateway/github");
GATEWAY_GITHUB_ROUTER.get("*", cache({
cacheName: "github-emojis",
cacheControl: "max-age=3600, immutable",
}));
GATEWAY_GITHUB_ROUTER.openapi(GITHUB_EMOJIS_ROUTE, async (c) => {
const response = await fetch("https://api.github.com/emojis", {
headers: {
"Accept": "application/vnd.github.v3+json",
"X-GitHub-Api-Version": "2022-11-28",
"Authorization": `Bearer ${c.env.GITHUB_TOKEN}`,
"User-Agent": "luxass - (api.mojis.dev)",
},
});
if (!response.ok) {
const errorData = await response.text();
console.error(`GitHub API error: ${response.status} - ${errorData}`);
return createError(c, 500, "Internal Server Error");
}
const emojis = await response.json<Record<string, string>>();
return c.json(emojis, 200);
});