A React + TypeScript + Vite application demonstrating various Supabase Edge Functions patterns, including database operations, file uploads with presigned URLs, and CORS handling.
Try it out: https://supa-edge-test.netlify.app/
Test all the edge functions and HTTP methods live in your browser!
This playground demonstrates:
- Edge Function Invocations: Call Supabase Edge Functions from a React frontend
- Database CRUD Operations: Create, Read, Update, and Delete operations through edge functions
- File Uploads: Upload files to Supabase Storage using presigned URLs
- CORS Configuration: Proper handling of CORS preflight requests in edge functions
- HTTP DELETE Method: Demonstrates the fix for GitHub Issue #1466 - using actual HTTP DELETE with proper CORS headers
A simple function that demonstrates basic edge function setup with proper CORS headers.
Tests CORS configuration from the browser, using shared CORS headers.
Performs database operations on the todos table:
- Create new todos
- Read all todos
- Update todo status
- Delete todos
Generates presigned URLs for direct file uploads to Supabase Storage, with automatic URL fixing for local development.
Demonstrates using actual HTTP DELETE method with proper CORS configuration. This function showcases the fix for GitHub Issue #1466 where DELETE requests failed due to missing Access-Control-Allow-Methods header.
Comprehensive demonstration of all HTTP methods (GET, POST, PUT, PATCH, DELETE) in a single function. Shows the difference between "simple" methods (GET, POST) that don't require Access-Control-Allow-Methods and "non-simple" methods (PUT, PATCH, DELETE) that require it for CORS preflight to succeed.
├── src/
│ ├── App.tsx # Main UI with all feature demos
│ ├── supabaseClient.ts # Supabase client configuration
│ └── ...
├── supabase/
│ ├── functions/
│ │ ├── _shared/
│ │ │ └── cors.ts # Shared CORS configuration with Access-Control-Allow-Methods
│ │ ├── hello-world/
│ │ ├── test-cors/
│ │ ├── db-ops/
│ │ ├── generate-upload-url/
│ │ ├── delete-method/ # HTTP DELETE method demo (Issue #1466 fix)
│ │ └── all-http-methods/ # Complete HTTP methods CORS demonstration
│ └── migrations/
│ ├── create_test_tables.sql
│ ├── create_test_uploads_bucket.sql
│ ├── add_todos_rls_policies.sql
│ └── remove_todos_user_fkey.sql
└── ...
- Node.js 18+
- Supabase CLI installed
- A Supabase project
- Clone the repository and install dependencies:
npm install- Start local Supabase:
supabase start- Apply migrations:
supabase db reset- Serve edge functions locally:
supabase functions serve- Start the dev server:
npm run devThe app will run at http://localhost:5173 and use the local Supabase instance.
supabase functions deploy hello-world
supabase functions deploy test-cors
supabase functions deploy db-ops
supabase functions deploy generate-upload-url
supabase functions deploy delete-method
supabase functions deploy all-http-methodssupabase db pushTo test against your production Supabase instance, rename .env.local to disable local configuration:
mv .env.local .env.local.backupThen restart your dev server. The app will now use the production Supabase URL from .env.
To switch back to local:
mv .env.local.backup .env.localDuring development, we discovered that edge functions require proper CORS handling to work from browser clients:
Problem: The hello-world function initially returned a 500 error on OPTIONS preflight requests because it:
- Didn't handle OPTIONS requests
- Didn't include CORS headers
- Tried to parse JSON from empty OPTIONS request bodies
Solution: All edge functions now:
- Check for OPTIONS requests and return early with CORS headers
- Import shared CORS configuration from
_shared/cors.ts - Include CORS headers in all responses
This project also demonstrates the fix for GitHub Issue #1466, where users reported CORS errors when using actual HTTP DELETE methods with Supabase Edge Functions.
Root Cause: The Access-Control-Allow-Methods header was missing from CORS configuration. This header is required for "non-simple" HTTP methods like DELETE, PUT, and PATCH.
The Fix: Updated supabase/functions/_shared/cors.ts to include:
'Access-Control-Allow-Methods': 'GET, POST, PUT, PATCH, DELETE, OPTIONS'Two Valid Approaches:
- POST with operation type (simpler CORS) - Used in
db-opsfunction - Actual HTTP DELETE method (more RESTful) - Demonstrated in
delete-methodfunction
Both approaches work, but they have different CORS requirements. See DELETE-CORS-FIX.md for a comprehensive explanation.
Complete HTTP Methods Testing: The all-http-methods function provides a comprehensive demonstration of all HTTP methods:
- Simple methods (GET, POST): Work with basic CORS headers
- Non-simple methods (PUT, PATCH, DELETE): Require
Access-Control-Allow-Methodsheader
This clearly shows why the CORS fix is necessary for non-simple methods.
This project was created to investigate supabase-js issue #1662 regarding CORS with presigned upload URLs. While the issue described CORS problems with direct file uploads, we found that:
- Local and production Supabase Storage properly handle CORS for presigned URLs
- The actual CORS issues were in edge functions that didn't handle OPTIONS requests
- Proper CORS configuration in edge functions is essential for browser clients
- React 19
- TypeScript
- Vite
- Supabase (Edge Functions, Storage, Database)
- @supabase/supabase-js