Self-Hosting Guide

Set up and maintain your own c15t instance for full control over your consent management backend

This guide shows you how to set up a self-hosted c15t instance, giving you complete control over your consent management system.

Looking for an easier way? consent.io offers a fully managed c15t backend with minimal setup. See the Server-Based Storage page for details.

Install @c15t/backend Package

npm install @c15t/backend

Create a c15t instance

Separating your configuration from the API route handler makes it easier to manage and update your c15t instance.

First, create a separate file for your c15t instance configuration:

c15t.ts
import { c15tInstance } from '@c15t/backend';
import { memoryAdapter } from '@c15t/backend/pkgs/db-adapters/adapters/memory-adapter';
 
export const instance = c15tInstance({
	appName: 'Example App',
	basePath: '/api/c15t',
	database: memoryAdapter({}),
	trustedOrigins: ['http://localhost:3000', 'http://localhost:8787'],
});

This example uses the Memory Adapter for simple in-memory storage that's perfect for development and testing. Data is stored in RAM and doesn't persist when the server restarts.

Then, create a catch-all API route that imports and uses this instance:

app/api/c15t/[...all]/route.ts
import { toNextHandler } from '@c15t/backend/integrations/next';
import { instance } from '../c15t';
 
export const { GET, POST, OPTIONS } = toNextHandler(instance);
app/api/c15t/[...all]/route.ts
import { toNextHandler } from '@c15t/backend/integrations/next';
import { instance } from '../c15t';
 
export const { GET, POST, OPTIONS } = toNextHandler(instance);

This approach separates your instance configuration from the route handler, making it easier for CLI tools and migration utilities to locate and work with your c15t instance.

Configure Your App to Use the API Route

Update your ConsentManagerOptions to point to your new API route:

app/layout.tsx
const options: ConsentManagerOptions = {
	mode: 'c15t',
	backendURL: 'http://localhost:8787', // Allows partial paths e.g. /api/c15t
};

Database Options

For production use, the Memory Adapter is not recommended as data is lost when the server restarts.

For production use, you should consider using a persistent database. c15t supports several database adapters:

These adapters can connect to various database backends:

PostgreSQL is recommended for production deployments due to its robust feature set and reliability.

See the Database Adapters documentation for complete implementation details.

Next Steps

On this page

c15t.com