Edge Functions

Code at the Edge

Run JavaScript at the edge with three function types. Auth middleware, content filters, and standard functions - with KV stores and AI-powered code assistance.

Edge Functions
Active
Request /api/user
Standard Function EXECUTED
geo: "AU" + enriched
Auth Middleware 201 ACCESS
JWT valid โ†’ proceed
Content Filter STREAMING
inject script
Response 200 transformed
~2ms latency KV store
View docs
3
Function Types
KV
Store Support
Monaco
Code Editor
AI
Code Assist
Standard Functions

Process Requests & Responses

Standard edge functions run on every matching request. Build API proxies, transform requests, enrich data from external APIs, or implement rate limiting and geo-routing.

  • API proxies with auth
  • Request transformation
  • Data enrichment
  • Geo-location routing

Edge function docs

Edge Function Standard
Running
Incoming Request
GET /api/data cf-ipcountry: AU
Function Execution
12ms
KV.get('cache-key') HIT
fetch('api.example.com') skipped
Geo routing: AU โ†’ au.origin
Response
200 OK application/json 1.2kb
Edge compute KV store
View logs
Auth Middleware /protected/*
Request
GET /protected/data
Authorization: Bearer eyJhbGciOiJI...
Authentication Checks
Token present
Yes
JWT signature valid
Valid
Token not expired
Active
Has required scope
read:data
Grant Access
201
Continue to origin
Deny Access
401
Return error
JWT validation Chainable
View docs
Auth Middleware

Protect Routes with Authentication

Auth middleware protects routes by validating tokens, sessions, or custom logic. Return status 201 to grant access, or 401/403 to deny. Chain multiple middleware for layered security.

  • JWT validation
  • Session checks
  • IP whitelisting
  • Chainable middleware

Auth middleware docs

Content Filters

Transform HTML Responses

Content filters transform HTML responses as they stream to clients. Extend TransformStream to inject scripts, replace content, add analytics, or modify HTML in real-time.

  • HTML transformation
  • Script injection
  • Content replacement
  • Analytics insertion

Content filter docs

Content Filter TransformStream
Streaming
Original HTML from origin
<html>
<head>...</head>
<body>
...content...
</body>
</html>
Transformations
1 Inject analytics before </body>
2 Add security headers
3 Replace placeholder text
Modified HTML to client
<html>
<head>...</head>
<body>
...content...
<script src="/analytics.js"></script>
</body>
</html>
Streaming Script inject
View docs

Start Building at the Edge

Create edge functions, auth middleware, and content filters from the dashboard.

3 function types
KV store support
Monaco code editor
AI code assistance