sleeplessS
Convex Community5mo ago
4 replies
sleepless

http endpoints, have to define twice to handle OPTIONS / preflight requests?

For an http POST endpoint do I have to define the same endpoint also with method OPTIONS to handle preflight requests?

Otherwise I get a 404 options even thought I'm setting method: "POST" in my fetch request.

ended up with something like this
  // Handle CORS preflight requests
  if (request.method === "OPTIONS") {
    return new Response(null, {
      status: 200,
      headers: {
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Methods": "POST, OPTIONS",
        "Access-Control-Allow-Headers": "Content-Type",
      },
    });
  }


Not really an issue just figured I'd ask for learning purposes, I think I've vaguely figured out what's going on but took a while to figure out why it wasn't working
Was this page helpful?