Skip to content

Commit

Permalink
feat: add new route handler
Browse files Browse the repository at this point in the history
  • Loading branch information
H01001000 committed Jul 18, 2024
1 parent 245de4e commit 9ef19a2
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions site/src/app/api/kv/[key]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

// Next.js Edge API Route Handlers: https://nextjs.org/docs/app/building-your-application/routing/router-handlers#edge-and-nodejs-runtimes

import type { NextRequest } from 'next/server'
import type { KVNamespace } from '@cloudflare/workers-types'
import { NextResponse } from 'next/server'
import { NextApiRequest } from 'next';

export const runtime = 'edge'

export async function GET(req: NextRequest, { params }: { params: { key: string } }) {
const { KV_STATUS_PAGE } = (process.env as unknown as { KV_STATUS_PAGE: KVNamespace });
const { key } = params
const data = await KV_STATUS_PAGE.get(key, { type: 'text' });
if (data === null)
return new NextResponse('Not Found', {
status: 404,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
},
})
return new NextResponse(data, {
status: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
},
})
}

0 comments on commit 9ef19a2

Please sign in to comment.