Supabase-workers

Proof-of-concept for making API requests to Supabase in Cloudflare Workers

APACHE-2.0 License

Stars
9

supabase-workers 👷

This codebase is a proof-of-concept for making API requests to Supabase inside of a Cloudflare Workers serverless function.

Supabase's JavaScript client doesn't work directly in Workers without using Webpack's externals feature to replace cross-fetch with the native fetch API in Workers, as seen here.

You can see an example of this API at https://supabase-workers.riteshpuvvada.workers.dev:

  • https://supabase-workers.riteshpuvvada.workers.dev/users: select all users
  • https://supabase-workers.riteshpuvvada.workers.dev/users/:id: query for a user by id
  • https://supabase-workers.riteshpuvvada.workers.dev/*: all other requests are redirected to this GitHub project

To deploy your own version, clone or fork the project, replace the account_id value in wrangler.toml with your own, and then set two secrets using wrangler secret put:

  • SUPABASE_API_KEY: anon/public key available in your Supabase project's "API settings"
  • SUPABASE_URL: RESTful endpoint URL available in your Supabase project's "API settings"

This project is built on TypeScript using itty-router and could easily be extended to provide a RESTful interface to your Supabase data, without needing to expose any API credentials.