Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use zValidator for query with POST requests #113

Closed
kolyasapphire opened this issue Dec 14, 2023 · 6 comments
Closed

Unable to use zValidator for query with POST requests #113

kolyasapphire opened this issue Dec 14, 2023 · 6 comments

Comments

@kolyasapphire
Copy link

Hey! First of all thank you so much for your Hono and the Node.js adapter work - they are awesome!

I've noticed that this code works fine with just Hono on Vercel inside Next.js:

import { Hono } from 'hono'
import { zValidator } from '@hono/zod-validator'
import { handle } from 'hono/vercel'
import * as z from 'zod'

const schema = z.object({
  test: z.string(),
})

const app = new Hono().post('*', zValidator('query', schema), (c) =>
  c.text('test')
)

export default handle(app)

export const runtime = 'edge'

But when using the honojs/node-server like so:

import { Hono } from 'hono'
import { zValidator } from '@hono/zod-validator'
import { handle } from '@hono/node-server/vercel'
import * as z from 'zod'

const schema = z.object({
  test: z.string(),
})

const app = new Hono().post('*', zValidator('query', schema), (c) =>
  c.text('test')
)

export default handle(app)

I am getting:

TypeError: Response body object should not be disturbed or locked
at extractBody (node:internal/deps/undici/undici:5178:17)
at new Request (node:internal/deps/undici/undici:6160:48)
at newRequestFromIncoming (file:///hono-tests/node_modules/@hono/node-server/dist/vercel.mjs:160:10)
at [getRequestCache] (file:///hono-tests/node_modules/@hono/node-server/dist/vercel.mjs:173:35)
at Request.get (file:///hono-tests/node_modules/@hono/node-server/dist/vercel.mjs:192:35)
at HonoRequest.header (file:///hono-tests/node_modules/hono/dist/request.js:73:23)
at /hono-tests/node_modules/hono/dist/cjs/validator/validator.js:29:31
at dispatch (file:///hono-tests/node_modules/hono/dist/compose.js:29:23)
at file:///hono-tests/node_modules/hono/dist/compose.js:6:12
at file:///hono-tests/node_modules/hono/dist/hono-base.js:247:31
at Hono.dispatch (file:///hono-tests/node_modules/hono/dist/hono-base.js:257:7)
at fetch (file:///hono-tests/node_modules/hono/dist/hono-base.js:59:19)
at file:///hono-tests/node_modules/@hono/node-server/dist/vercel.mjs:275:13
at /hono-tests/node_modules/next/dist/compiled/next-server/pages-api.runtime.dev.js:21:3039
at /hono-tests/node_modules/next/dist/server/lib/trace/tracer.js:133:36

Without zValidator it also works as expected.

@yusukebe
Copy link
Member

Hi @kolyasapphire,

I've tried running the code, but it seems to work fine on my environment. Therefore, the issue might be related to package dependencies. Could you create a GitHub project to reproduce the issue? Once you do that, I can investigate it.

@kolyasapphire
Copy link
Author

Hey @yusukebe,

Absolutely, here you go:
https://codesandbox.io/p/devbox/angry-voice-26yy73

Screenshot 2023-12-16 at 21 38 15

Thanks for looking into this!

@yusukebe
Copy link
Member

@kolyasapphire

Thanks! You might fix this issue with adding the following:

export const config = {
  api: {
    bodyParser: false
  }
}

This is related to #84

@herrAlison
Copy link

import requests

with requests.session() as session:

url = 'https://register.fdsinstitut.com/ext/index.php'

headers = {}
cookies = {}
donnees = {}

reponse = session.post(url, headers=headers, cookies=cookies, data=donnees)

print(reponse.text)

@herrAlison
Copy link

dieses programm löuft nicht richtig ,

@kolyasapphire
Copy link
Author

Thanks @yusukebe! Works as expected now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants