diff options
Diffstat (limited to 'pages/api/graphql.ts')
| -rw-r--r-- | pages/api/graphql.ts | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/pages/api/graphql.ts b/pages/api/graphql.ts new file mode 100644 index 0000000..92c3eff --- /dev/null +++ b/pages/api/graphql.ts @@ -0,0 +1,49 @@ +import type { NextRequest } from 'next/server' + +const API_ENDPOINT = 'https://api.github.com/graphql' + +const graphQLEndpoint = async (req: NextRequest) => { + if (req.method !== 'POST') { + return new Response('Method Not Allowed', { + status: 405, + headers: { + 'cache-control': 'max-age=0, public' + } + }) + } + + const response = await fetch(API_ENDPOINT, { + method: 'POST', + headers: { + Accept: 'application/json', + Authorization: `bearer ${process.env.GITHUB_TOKEN}`, + 'content-type': 'application/json' + }, + body: req.body + }) + + if (!response.ok) { + return new Response(await response.text(), { + status: response.status, + headers: { + 'cache-control': 'public, max-age=0' + } + }) + } + + const text = await response.text() + return new Response(text, { + status: 200, + headers: { + 'content-type': 'application/json', + 'cache-control': + 'public, immutable, no-transform, max-age=60, s-maxage=600' + } + }) +} + +export const config = { + runtime: 'experimental-edge' +} + +export default graphQLEndpoint |
