Simple Supabase to Cloudflare Pages _redirects generator example. There are better ways to manage your redirects, but hey, this is fun!
This project is mainly a demonstration of Supabase Function Hooks on data change, combined with Cloudflare Pages Deploy Hooks.
- Deploy this repository to Cloudflare Pages project with
SUPABASE_KEYandSUPABASE_URLbuild variables (more info in Cloudflare Pages settings below) - Create Cloudflare Pages Deploy Hook in Project Settings and save it for step 4.
- Run init SQL to create the
redirectstable (SQL -> New Query) - Add Supabase Function Hook for table
redirectson all updates (Database -> Function Hooks) - Add or edit some redirects in the Supabase Table Editor, all changes should trigger Pages build in the background (takes ~1 minute to deploy)
create table public.redirects (
id uuid not null unique primary key default extensions.uuid_generate_v4(),
source text default '/' not null,
destination text null,
code int2 not null default 302,
active bool default true not null
);- build command is
yarn run build - build env
SUPABASE_KEYis the client key (API -> Authentication) - build env
SUPABASE_URLis your Supabase endpoint, e.g.https://xxxxyyyy.supabase.co
- table
redirects - all (Insert, Update, Delete) event
- POST method
- URL is the Cloudflare Pages Deploy Hook
- Pages currently allow 100 redirect rules only, so more than 100 rules will be ignored.
- There is no UI apart of the Supabase - it works just fine though.
