@whi/cf-routing - v0.2.0
    Preparing search index...

    Function createCorsHandler

    • Creates a CORS handler middleware

      Parameters

      • corsHeaders: Record<string, string>

        CORS headers to include in responses

      Returns (
          request: Request,
          handler: (request: Request) => Promise<Response>,
      ) => Promise<Response>

      A function that adds CORS headers to responses

      const customCorsHeaders = {
      'Access-Control-Allow-Origin': 'https://example.com',
      'Access-Control-Allow-Methods': 'GET, POST'
      };

      const corsHandler = createCorsHandler(customCorsHeaders);
      const response = await corsHandler(request, async (req) => {
      return new Response('Hello');
      });