route handler not returning response
Answered
useless posted this in #help-forum
uselessOP
i have a rout handler on
the route.ts
and when i visit it, it works fine and gives me the needed response.
however, when i call this in a
what should i do to get the response in the pages
/api/template?id=xxxxxxxxthe route.ts
export async function GET(request: Request) {
const { searchParams } = new URL(request.url)
const id = searchParams.get('id')
const { data, error } = await supabase
.from('templates')
.select(`id, parent, body`)
.eq('id', id)
.single()
if (data) {
return NextResponse.json(data)
}
if (error) {
return NextResponse.json(error)
}
}and when i visit it, it works fine and gives me the needed response.
however, when i call this in a
page.tsx i get this response body: ReadableStream
bodyUsed: false
headers: Headers {}
ok: true
redirected: false
status: 200
statusText: "OK"
type: "basic"
url: "http://localhost:3000/api/template?id=xxxxxxx"what should i do to get the response in the pages
4 Replies
Asiatic Lion
Read the data in the client with
await res.json()Answer
@Asiatic Lion Read the data in the client with `await res.json()`
uselessOP
it worked with your solution, it's like magic!!