Hello everyone!
I’m developing a Shopify app and facing a CORS error when trying to send a request from the storefront to my server.
Error:
Access to fetch at 'https://multimedia-arg-such-transcript.trycloudflare.com/api/assistant?query=Hello' from origin 'https://getvoicecart.myshopify.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.
Hi @Curzey, I’m facing a similar issue in my app. After hosting my Shopify app, whenever I try to call the API route endpoint with GET/POST/DELETE requests (e.g., /api/getUser) from the storefront (i.e., theme extension JavaScript file), I encounter a CORS error.
The following error appears in the terminal:
Error: You made an OPTIONS request to “/api/send/otp” but did not provide a loader for route “routes/api.send.otp”, so there is no way to handle the request.
at getInternalRouterError (/app/node_modules/@remix-run/router/router.ts:5513:5)
at loadRouteData (/app/node_modules/@remix-run/router/router.ts:3946:13)
at queryImpl (/app/node_modules/@remix-run/router/router.ts:3742:26)
at Object.queryRoute (/app/node_modules/@remix-run/router/router.ts:3675:24)
at handleResourceRequest (/app/node_modules/@remix-run/server-runtime/dist/server.js:402:40)
at requestHandler (/app/node_modules/@remix-run/server-runtime/dist/server.js:156:24)
at /app/node_modules/@remix-run/express/dist/server.js:41:28
at processTicksAndRejections (node:internal/process/task_queues:95:5)
OPTIONS /api/send/otp 400 - - 2300.261 ms
The next step, to transfer the user’s cookie from the storefront: The solution to the problem was only to pass the cookie inside the request, if you use the cors policy it won’t work, because cloudflare rewrites it.