animeyeet
animeyeet2y ago

CORS Issue

any idea
15 Replies
jamwt
jamwt2y ago
Can you paste the output of curl -v $YOUR SITE ? so we can see the headers coming from the http action?
jamwt
jamwt2y ago
I don't see the header in there next question in your convex dashboard npx convex dashboard, do you see this http action having the code body you expect? ah, actually. I see the issue. this was a 404 so the router isn't working. what does your route adding code look like? and are you default exporting a router from a file called http.ts ?
animeyeet
animeyeetOP2y ago
http.route({ path: "/test", method: "OPTIONS", handler: httpAction(async (_, request) => { // Make sure the necessary headers are present // for this to be a valid pre-flight request const headers = request.headers; if ( headers.get("Origin") !== null && headers.get("Access-Control-Request-Method") !== null && headers.get("Access-Control-Request-Headers") !== null ) { return new Response(null, { headers: new Headers({ // e.g. https://mywebsite.com "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Methods": "POST", "Access-Control-Allow-Headers": "Content-Type", "Access-Control-Max-Age": "86400", "Content-Type": "application/json", }), }); } else { return new Response(); } }), }); // Define additional routes http.route({ path: "/test", method: "POST", handler: doSomething, }); copy pasta from the docs basically
jamwt
jamwt2y ago
and that http object is exported? double checking that, but then our curl test probably didn't work because it was a GET
animeyeet
animeyeetOP2y ago
No description
jamwt
jamwt2y ago
cool and everything looks good in the dashboard? the functions are syncing, npx convex dev is up and running?
animeyeet
animeyeetOP2y ago
curl -d '{ "data": [], "apiKey": "Hello world" }' \ -H 'content-type: application/json' "https://calculating-xyz.convex.site/test"
{"code":"Uncaught Error: Uncaught something "}% -> is error is probably from the internalAction that i'm running wowo just realize your the ceo of convex just for the personal portfolio website you build a whole baas 😁
jamwt
jamwt2y ago
🙂 next step I'd ask is if you can go into chrome devtools and watch the network request go by. do you see the OPTIONS request to your site? we can inspect the headers to make sure everything is okay there
animeyeet
animeyeetOP2y ago
ok i think i got the issue so basically the internalAction was doing processing on bunch of data and in some cases it fails and throws error
animeyeet
animeyeetOP2y ago
No description
animeyeet
animeyeetOP2y ago
and the fetch some how shows cors error in this case
jamwt
jamwt2y ago
ah, interesting
animeyeet
animeyeetOP2y ago
Ya, i double checked it. If the internal action doesn't fail in any case then it doesn't give any sort of error

Did you find this page helpful?