N
Nuxt5d ago
lkjimy

H3 doesn't support body content on SEARCH method?

I'm trying to proxy an API, by following Alex's video on proxies. I want to be able to use the SEARCH http method. I tried using routeRules, which works, but it doesn't seem to pass in the body to the destiny endpoint, returning unfiltered data.
// ...
runtimeConfig: {
backendUrl: 'http://my-api-endoint.com'
},

routeRules: {
'/api/v1/**': {
proxy: 'http://my-api-endoint.com/**'
}
},

// ...
// ...
runtimeConfig: {
backendUrl: 'http://my-api-endoint.com'
},

routeRules: {
'/api/v1/**': {
proxy: 'http://my-api-endoint.com/**'
}
},

// ...
Also tried using the server route method, which also works, but with the same result. The body does not seem to be applied to the destiny endpoint.
// server/api/v2/[...].js

import { joinURL } from 'ufo'

export default defineEventHandler(async (event) => {
const backendUrl = useRuntimeConfig().backendUrl
const path = event.path.replace(/^\/api\/v2\//, '')
const target = joinURL(backendUrl, path)

// console.log(event)
// const body = await readBody(event)
// console.log(body)

return proxyRequest(event, target)
})
// server/api/v2/[...].js

import { joinURL } from 'ufo'

export default defineEventHandler(async (event) => {
const backendUrl = useRuntimeConfig().backendUrl
const path = event.path.replace(/^\/api\/v2\//, '')
const target = joinURL(backendUrl, path)

// console.log(event)
// const body = await readBody(event)
// console.log(body)

return proxyRequest(event, target)
})
When I try to read the body...
// ...
const body = await readBody(event)
// ...
// ...
const body = await readBody(event)
// ...
... and use SEARCH (response in the image). If I change the request to POST, the readbody seems to to work as expected. So, H3 does not support body on SEARCH method? ... Or am I missing something on defineEventHandler?
No description
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server