File tree Expand file tree Collapse file tree
apps/pay-test-exchange/app/api Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { getCloudflareContext } from '@opennextjs/cloudflare'
2- import type { NextRequest } from 'next/server'
2+ import { type NextRequest , NextResponse } from 'next/server'
33
4- export async function GET ( request : NextRequest ) {
4+ interface StatusRequest {
5+ sessionId : string
6+ }
7+
8+ export async function POST ( request : NextRequest ) {
59 const { env } = getCloudflareContext ( )
610
7- const sessionId = request . nextUrl . searchParams . get ( 'sessionId' )
11+ const { sessionId } = await request . json < StatusRequest > ( )
812
913 if ( ! sessionId ) {
10- return new Response ( 'No sessionId provided' , { status : 400 } )
14+ return NextResponse . json ( { error : 'No sessionId provided' } , { status : 400 } )
1115 }
1216
1317 const session = await env . SESSIONID_STORAGE . get ( sessionId )
1418
1519 if ( ! session ) {
16- return new Response ( 'Session not found' , { status : 404 } )
20+ return NextResponse . json ( { error : 'Session not found' } , { status : 404 } )
1721 }
1822
19- return new Response ( session )
23+ return NextResponse . json ( JSON . parse ( session ) )
2024}
Original file line number Diff line number Diff line change 11import { getCloudflareContext } from '@opennextjs/cloudflare'
2- import { NextRequest } from 'next/server'
2+ import { NextRequest , NextResponse } from 'next/server'
33
44import { Session } from '@/lib/types'
55
@@ -27,7 +27,7 @@ export async function POST(request: NextRequest) {
2727 } as Session )
2828 )
2929
30- return new Response ( 'Session created' , { status : 200 } )
30+ return NextResponse . json ( { message : 'Session created' } , { status : 200 } )
3131 }
3232
3333 const session = JSON . parse ( sessionData ) as Session
@@ -36,7 +36,7 @@ export async function POST(request: NextRequest) {
3636 const { status } = ( await request . json ( ) ) as UpdateSessionRequest
3737
3838 if ( status !== 'success' && status !== 'error' ) {
39- return new Response ( 'Invalid status provided' , { status : 400 } )
39+ return NextResponse . json ( { error : 'Invalid status provided' } , { status : 400 } )
4040 }
4141
4242 session . status = status
@@ -47,5 +47,5 @@ export async function POST(request: NextRequest) {
4747
4848 await env . SESSIONID_STORAGE . put ( sessionId , JSON . stringify ( session ) )
4949
50- return new Response ( 'Session updated' , { status : 200 } )
50+ return NextResponse . json ( { message : 'Session updated' } , { status : 200 } )
5151}
You can’t perform that action at this time.
0 commit comments