Skip to content

Configure the settings for CORS but CORS error is happened on Chrome. #3488

Closed Answered by safwanyp
sabotenpillow asked this question in Q&A
Discussion options

You must be logged in to vote

This seems like a simple issue of ordering. In the code you provided, you are "using" the CORS middleware after the route. If you switch these around, you do not need to set the headers explicitly like so:

app.use(
  cors({
    origin: ["http://localhost:4173"],
    credentials: true,
  }),
);

app.post("/signin", c => {
  c.status(201);
  return c.body("this is body");
});

const port = 3000;
console.log(`Server is running on port ${port}`);

serve({
  fetch: app.fetch,
  port,
});

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by sabotenpillow
Comment options

You must be logged in to vote
1 reply
@davimateus1
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants