diff options
Diffstat (limited to 'pages/api/stats.ts')
| -rw-r--r-- | pages/api/stats.ts | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/pages/api/stats.ts b/pages/api/stats.ts new file mode 100644 index 0000000..d557939 --- /dev/null +++ b/pages/api/stats.ts @@ -0,0 +1,42 @@ +import type { NextRequest } from 'next/server' + +const statsEndpoint = async (req: NextRequest) => { + const response = await fetch( + `https://api.github.com/search/code?per_page=1&q=${encodeURIComponent( + 'socialify.git.ci' + )}`, + { + method: 'GET', + headers: { + Accept: 'application/vnd.github.v3+json', + Authorization: `bearer ${process.env.GITHUB_TOKEN}`, + 'content-type': 'application/json' + } + } + ) + + if (!response.ok) { + return new Response(await response.text(), { + status: response.status, + headers: { + 'cache-control': 'public, max-age=0' + } + }) + } + + const json = await response.json() + return new Response(JSON.stringify({ total_count: json.total_count }), { + status: 200, + headers: { + 'content-type': 'application/json', + 'cache-control': + 'public, immutable, no-transform, max-age=60, s-maxage=86400' + } + }) +} + +export const config = { + runtime: 'experimental-edge' +} + +export default statsEndpoint |
