File
Blob: src/workerd/api/tests/opennextjs/src/app/api/data/route.js
| 1 | // Copyright (c) 2026 Cloudflare, Inc. |
| 2 | // Licensed under the Apache 2.0 license found in the LICENSE file or at: |
| 3 | // https://opensource.org/licenses/Apache-2.0 |
| 4 | |
| 5 | import { NextResponse } from 'next/server'; |
| 6 | |
| 7 | export async function GET(request) { |
| 8 | const headers = {}; |
| 9 | request.headers.forEach((value, key) => { |
| 10 | headers[key] = value; |
| 11 | }); |
| 12 | |
| 13 | const searchParams = {}; |
| 14 | request.nextUrl.searchParams.forEach((value, key) => { |
| 15 | searchParams[key] = value; |
| 16 | }); |
| 17 | |
| 18 | return NextResponse.json({ |
| 19 | message: 'API response', |
| 20 | timestamp: Date.now(), |
| 21 | method: 'GET', |
| 22 | headers, |
| 23 | searchParams, |
| 24 | }); |
| 25 | } |
| 26 | |
| 27 | export async function POST(request) { |
| 28 | const body = await request.json().catch(() => ({})); |
| 29 | |
| 30 | return NextResponse.json({ |
| 31 | message: 'API response', |
| 32 | timestamp: Date.now(), |
| 33 | method: 'POST', |
| 34 | received: body, |
| 35 | }); |
| 36 | } |
| 37 | |
| 38 | export async function OPTIONS() { |
| 39 | return new NextResponse(null, { |
| 40 | status: 204, |
| 41 | headers: { |
| 42 | 'Access-Control-Allow-Origin': '*', |
| 43 | 'Access-Control-Allow-Methods': 'GET, POST, OPTIONS', |
| 44 | }, |
| 45 | }); |
| 46 | } |