-
-
Notifications
You must be signed in to change notification settings - Fork 638
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
CORS error issues when passing Content-Type: application/json
from the client
#1872
Comments
I can't reproduce it. Please share the minimal project to reproduce it. |
I confirm I can reproduce this. It only happens when:
I've been doing some digging and I believe it's related to this issue from Vercel: |
I just started a new Hono project with Bun and I'm encountering this issue as well. Version 3.12.6. My first time using Hono and can not for the life of me figure out what I'm doing wrong with my barebones setup that is pretty much like the OP's example. |
I went back and installed older version of hono to trace down when it did last work. I worked my way up from [email protected] but I never encountered the cors issue again. Even all the way back up to the latest version at 3.12.6? Perhaps there's a missing dependency in the latest package but the error is being swallowed? EDIT: |
Hi @frankieali This works fine on Bun. import { zValidator } from '@hono/zod-validator'
import { Hono } from 'hono'
import { cors } from 'hono/cors'
import { raw } from 'hono/html'
import { z } from 'zod'
const schema = z.object({
hello: z.string(),
})
const app = new Hono().basePath('/api')
app.use('/api/*', cors())
app.post('/test', zValidator('json', schema), (c) => {
const body = c.req.valid('json')
return c.json({ ok: true, body })
})
app.get('/', (c) => {
return c.html(
<html>
<body>
<script>
{raw(`
(async () => {
const res = await fetch("http://localhost:3000/api/test", {
method: "POST",
headers: { "Content-Type": "application/json", },
body: JSON.stringify({ hello: "world" }),
})
console.log(await res.json())
})();`)}
</script>
</body>
</html>
)
})
export default app |
I can't reproduce it on Bun. And it's not related to Vercel's matter. We can close it now |
What version of Hono are you using?
3.11.11
What runtime/platform is your app running on?
Vercel
What steps can reproduce the bug?
However, when using
zValidator
from@hono/zod-validator
, I experience this:What is the expected behavior?
I should get CORS to work when passing
Content-Type: application/json
from the client.What do you see instead?
No response
Additional information
Dependencies:
The text was updated successfully, but these errors were encountered: