Web Dev CodyW
Convex Community2y ago
21 replies
Web Dev Cody

Issue with Cors

I'm trying to add an http endpoint to convex which any application is able to send a request to, but it seems like maybe using * doesn't work?

this is my current handler for options, but it fails when my other domain tries to hit it

http.route({
  path: '/api/v1/feedback',
  method: 'OPTIONS',
  handler: httpAction(async (_, 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({
          'Access-Control-Allow-Origin': process.env.ALLOW_ORIGIN!,
          'Access-Control-Allow-Methods': 'POST',
          'Access-Control-Allow-Headers': 'Content-Type, Digest',
          'Access-Control-Max-Age': '86400',
        }),
      });
    } else {
      return new Response();
    }
  }),
});
Was this page helpful?