Skip to content

Commit 8bdc0b4

Browse files
chore: change api type and use json responses (#4706)
1 parent 4fb4bfb commit 8bdc0b4

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
import { 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
}

apps/pay-test-exchange/app/api/update/route.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getCloudflareContext } from '@opennextjs/cloudflare'
2-
import { NextRequest } from 'next/server'
2+
import { NextRequest, NextResponse } from 'next/server'
33

44
import { 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
}

0 commit comments

Comments
 (0)