H
Hono2w ago
Jacob

Getting cors issues even though i've set it up properly

So i have a frontend client using nextjs and a my api using hono with cloudflare. for some reason my frontend client returns a cors issues but the api proceeds with the requests and returns a 200 repsonse. my cors setup:
app.use("*", (c, next) => {
if (c.req.header("Origin") == c.env.FRONT_END_URL) {
return cors({
origin: [c.env.FRONT_END_URL, c.env.API_URL], // Front end url for cors
allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"], // Allow specific methods
allowHeaders: ["Content-Type", "Authorization"],
exposeHeaders: ["Content-Length"],
maxAge: 600,
credentials: true,
})(c, next);
}

return cors({
origin: "*", // Allow all origins
allowMethods: ["GET", "OPTIONS"],
})(c, next);
});
app.use("*", (c, next) => {
if (c.req.header("Origin") == c.env.FRONT_END_URL) {
return cors({
origin: [c.env.FRONT_END_URL, c.env.API_URL], // Front end url for cors
allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"], // Allow specific methods
allowHeaders: ["Content-Type", "Authorization"],
exposeHeaders: ["Content-Length"],
maxAge: 600,
credentials: true,
})(c, next);
}

return cors({
origin: "*", // Allow all origins
allowMethods: ["GET", "OPTIONS"],
})(c, next);
});
it used to be working however it has stopped. please check the attached items for more info. the repo: https://github.com/jacobsamo/BuzzTrip/tree/f8504ce6a164efc32eb2188eca24808cdf6d3fe9
GitHub
GitHub - jacobsamo/BuzzTrip at f8504ce6a164efc32eb2188eca24808cdf6d...
Plan the trip you've always dreamed of. Contribute to jacobsamo/BuzzTrip development by creating an account on GitHub.
1 Reply
ambergristle
ambergristle2w ago
hey! can you explain the issue you're facing in a little more detail? what do you mean by
my frontend client returns a cors issues
what do you expect to happen, and what's actually going on?

Did you find this page helpful?