Edge Functions
Serverless event processors that run your JavaScript code on every matching event. Transform, filter, enrich, or route events before they reach subscribers.
How It Works
- You write a JavaScript function in the dashboard
- Configure which channels and events trigger it
- When a matching event is broadcast, your function runs
- The function can modify the data, drop the event, or pass it through
Functions run in a sandboxed Node.js process with a 10-second timeout.
Creating a Function
Go to your app → Edge Functions → Create Function.
// event = { channel, event, data }
// secrets = { API_KEY: 'your-key' }
// Return modified data, or null to drop the event
module.exports = async function(event, { secrets }) {
// Add a timestamp to every message
const data = JSON.parse(event.data);
data.processed_at = new Date().toISOString();
return JSON.stringify(data);
};
| Field | Description |
|---|---|
| Name | Human-readable name for the function |
| Trigger Event | Event name to match (* for all) |
| Channel Pattern | Glob pattern for channels (orders-*, * for all) |
| Code | JavaScript function body |
Function Secrets
Store API keys and credentials as encrypted environment variables. Access them in your function via secrets.KEY.
Go to Edge Functions → Secrets tab → Add Secret.
module.exports = async function(event, { secrets }) {
// Use secrets without hardcoding
const apiKey = secrets.OPENAI_KEY;
// ... call external API
};
Secrets are encrypted at rest and only decrypted at execution time.
Function Versioning
Every time you deploy a function, a new version is created. You can:
- Deploy New Version — saves the current code as the next version
- Rollback — instantly reverts to the previous version
- A/B Test — split traffic between versions by percentage
Go to Edge Functions → click Deploy New Version on any function.
Version history is preserved so you can always go back.
Function Pipelines
Chain multiple functions together in sequence:
validate → enrich → transform → route
Go to Edge Functions → Pipelines tab → Create Pipeline.
Each step can:
- Pass data to the next step
- Drop the event (stops the pipeline)
- Handle errors independently (
stop,skip, orsend to DLQ)
Function Marketplace
Browse and install pre-built functions contributed by the community.
Go to Edge Functions → Marketplace tab.
Categories:
- Rate Limiters — throttle events per user/channel
- Formatters — normalize data formats
- Filters — drop unwanted events
- Enrichers — add metadata from external sources
- Validators — check payload structure
- Transformers — reshape event data
Click Install to add a template to your app.
Test Runner
Test your functions without publishing real events.
Go to Edge Functions → Test Runner tab.
- Select a function
- Enter a mock event JSON
- Click Run Test
- See the result: PASS/FAIL, output data, execution time
Execution Details
| Property | Value |
|---|---|
| Runtime | Node.js (sandboxed process) |
| Timeout | 10 seconds |
| Max payload | Same as your plan limit |
| Secrets | Available via secrets parameter |
| Return | Modified data (string), or null to drop |
Error Handling
If your function throws an error:
- The event is delivered with the original data (not transformed)
- The error is logged in the function's execution log
- The error counter increments
Go Server Integration
When the Go relay server receives a broadcast, it calls the Laravel edge function API:
Go Server → POST /api/v1/apps/{appId}/functions/execute → Laravel → Node.js → Result
The Go server sends the event to Laravel, which runs matching functions in Node.js and returns the transformed data. The Go server then broadcasts the result to subscribers.
Set LARAVEL_URL environment variable on the Go server to point to your Laravel app.