94 lines
No EOL
3.5 KiB
Markdown
94 lines
No EOL
3.5 KiB
Markdown
---
|
|
tags:
|
|
- iso27DIY
|
|
- architecture
|
|
- SupaBase
|
|
- LLMgenerated
|
|
---
|
|
|
|
# SupaBase edge functions portability
|
|
|
|
Supabase Edge Functions are built on Deno and use web standards (see below), which makes them relatively portable compared to platform-specific serverless functions. Here's what you need to know about their transportability:
|
|
|
|
**What makes them portable:**
|
|
|
|
- They run on Deno runtime, which is available on multiple platforms
|
|
- Use standard Web APIs (fetch, Request, Response objects)
|
|
- Written in TypeScript/JavaScript
|
|
- Follow web standards rather than proprietary APIs
|
|
|
|
**Where you can potentially run them:**
|
|
|
|
- **Deno Deploy** - Most direct migration since it's the same runtime
|
|
- **Cloudflare Workers** - Good compatibility due to similar web standards approach
|
|
- **Vercel Edge Functions** - Also supports web standard APIs
|
|
- **Netlify Edge Functions** - Uses Deno runtime as well
|
|
- **Self-hosted Deno** - Can run on your own infrastructure
|
|
|
|
**Considerations for migration:**
|
|
|
|
- **Supabase-specific features** - Functions that use Supabase client libraries or database connections will need adaptation
|
|
- **Environment variables** - May need to reconfigure for different platforms
|
|
- **Database connections** - Will need to update connection strings and potentially authentication methods
|
|
- **Deployment configuration** - Each platform has its own deployment process
|
|
|
|
**Best practices for portability:**
|
|
|
|
- Keep business logic separate from platform-specific code
|
|
- Use standard web APIs where possible
|
|
- Abstract database connections and external service calls
|
|
- Use environment variables for configuration
|
|
|
|
The code itself is generally portable, but you'll need to handle platform-specific configurations and potentially refactor any Supabase-specific integrations when moving to other platforms.
|
|
|
|
## Web standards
|
|
|
|
Supabase Edge Functions use several key web standards that make them portable across modern serverless platforms:
|
|
|
|
**Core Web APIs:**
|
|
|
|
- **Request/Response API** - Standard HTTP request and response objects
|
|
- **Fetch API** - For making HTTP requests to external services
|
|
- **URL API** - For parsing and manipulating URLs
|
|
- **Headers API** - For working with HTTP headers
|
|
- **ReadableStream/WritableStream** - For streaming data
|
|
|
|
**JavaScript/Web Platform Standards:**
|
|
|
|
- **Web Streams API** - For handling streaming data
|
|
- **TextEncoder/TextDecoder** - For encoding/decoding text
|
|
- **AbortController/AbortSignal** - For canceling operations
|
|
- **FormData** - For handling form submissions
|
|
- **URLSearchParams** - For working with query parameters
|
|
|
|
**Async/Promise Standards:**
|
|
|
|
- **Promise API** - Standard promise handling
|
|
- **async/await** - Modern asynchronous JavaScript syntax
|
|
|
|
**Crypto and Security:**
|
|
|
|
- **Web Crypto API** - For cryptographic operations (hashing, encryption)
|
|
- **Crypto.randomUUID()** - For generating UUIDs
|
|
|
|
**Data Handling:**
|
|
|
|
- **JSON** - Standard JSON parsing and stringification
|
|
- **Blob API** - For handling binary data
|
|
- **ArrayBuffer** - For working with binary data
|
|
|
|
**Example of standard usage:**
|
|
|
|
```javascript
|
|
// Standard Request/Response pattern
|
|
export default async function handler(req: Request): Promise<Response> {
|
|
const url = new URL(req.url)
|
|
const data = await req.json()
|
|
|
|
return new Response(JSON.stringify({ message: 'Hello' }), {
|
|
headers: { 'Content-Type': 'application/json' }
|
|
})
|
|
}
|
|
```
|
|
|
|
These standards are what make Edge Functions compatible with platforms like Cloudflare Workers, Vercel Edge Functions, and Netlify Edge Functions, since they all implement the same web standard APIs rather than proprietary interfaces. |