sleepless
sleepless6d ago

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",
},
});
}
// 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
3 Replies
Convex Bot
Convex Bot6d ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
sleepless
sleeplessOP4d ago
lovely thanks

Did you find this page helpful?