c15t
/
C15T Logo
Select a version
Frameworks
Welcome to c15t Docs
Introduction to Consent Management (c15t)
AI Tools Integrations
OSS
Contributing to c15t.com
License
Building Privacy Tools in the Open
Legal
Cookie Policy
Privacy Policy
C15T Logo
HomeFrontendIntegrationsSelf HostChangelog
xbskydiscordgithub1.4k
c15t
/
C15T Logo
Select a version
Frameworks
Welcome to c15t Docs
Introduction to Consent Management (c15t)
AI Tools Integrations
OSS
Contributing to c15t.com
License
Building Privacy Tools in the Open
Legal
Cookie Policy
Privacy Policy
home-2Docs
chevron-rightSelf-host
chevron-rightV2
chevron-rightExamples
chevron-rightCloudflare

Cloudflare Workers

Example of self-hosting c15t and Cloudflare Workers.

Info

To view the full example, see the Cloudflare example repository.

src/index.ts
import { c15tInstance } from "@c15t/backend/v2";
import { kyselyAdapter } from "@c15t/backend/v2/db/adapters/kysely";
import { Kysely, PostgresDialect } from "kysely";
import { Pool } from "pg";

const handler = (env: Env) => {
  const instance = c15tInstance({
    appName: "c15t-self-host",
    basePath: "/api/c15t",
    adapter: kyselyAdapter({
      db: new Kysely({
        dialect: new PostgresDialect({
          pool: new Pool({
            connectionString: env.DATABASE_URL
          })
        })
      }),
      provider: "postgresql"
    }),

    trustedOrigins: ["localhost", "vercel.app"],
    advanced: {
      disableGeoLocation: true,
      openapi: {
        enabled: true
      }
    },
    logger: {
      level: "error"
    }
  });

  return async (request: Request): Promise<Response> => {
    try {
      return await instance.handler(request);
    } catch (error) {
      console.error("Error handling request:", error);

      return new Response(
        JSON.stringify({
          error: "Internal Server Error",
          message: error instanceof Error ? error.message : String(error)
        }),
        {
          status: 500,
          headers: { "Content-Type": "application/json" }
        }
      );
    }
  };
};

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    return await handler(env)(request);
  }
};
C15T Logo
Leverage native React components for seamless integration and high performance in a robust Consent Management solution that empowers your development team while prioritizing privacy and compliance.
Product
  • Documentation
  • Components
Company
  • GitHub
  • Contact
Legal
  • Privacy Policy
  • Cookie Policy
c15t