-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
}) | ||
} |