CORS Issue
Im using hono x bun for my backend and next js for my front end.
when i fetch the api it will return
"has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource."
i already set my cors settings, here i attached
someone had a solution ?
8 Replies
This is happening from a public URL? If so, you'd need to add that public URL in thi origin for your code.
i just test it on my localhost,
Your browser should show some information about the policy violation. It may include information about what headers you're requesting that are refused. Please share a screenshot or the response that you see in the browser.
I'm having the same problem, any solution, I have localhost:3000 and app.localhost:3000
Your browser should show some information about the policy violation. It may include information about what headers you're requesting that are refused. Please share a screenshot or the response that you see in the browser.
That's interesting. For a test, can you just harcode the cors like displayed here (https://hono.dev/docs/middleware/builtin/cors#usage)?
Does that work? If it does, I'd suggest reverting back to your original code and debugging what's going on in your local Hono
node_modules
. See https://github.com/honojs/hono/blob/main/src/middleware/cors/index.ts line 57.GitHub
hono/src/middleware/cors/index.ts at main · honojs/hono
Web framework built on Web Standards. Contribute to honojs/hono development by creating an account on GitHub.
CORS Middleware - Hono
Web framework built on Web Standards for Cloudflare Workers, Fastly Compute, Deno, Bun, Vercel, Node.js, and others. Fast, but not only fast.
I tried this way, as shown in the documentation, but it didn't work at all. I'll use the NextJs API anyway. Anyway, thank you very much for your attention.