Middleware Templates
These templates are copy-ready starting points for synchronous Middleware Node destinations. They are not SDKs. Adapt the decision logic, keep the request/response shape stable, and return fast enough for live routing.
Middleware receivers should:
- Treat every nested object and field as optional.
- Return JSON before
execute_timeout_mswith at least a250msinternal safety buffer. - Use a stable response field such as
decisionso routes can evaluatebody_json.decision. - Avoid logging the full payload because it can contain IPs, user agents, URL parameters, and action data.
- Keep external API client timeouts low - remember this is hot-path routing so design accordingly.
- Read secrets from environment variables instead of hardcoding them.
Recommended route conditions:
| Route | Condition |
|---|---|
| Approved | body_json.decision is approved |
| Rejected | body_json.decision is rejected |
| Review | body_json.decision is review |
| Default | No conditions; used for fallback, no-match, or delivery failure. |
AI Prompt
Copy this prompt into your AI tool, then paste the Middleware Nodes documentation after it if the tool needs more context.
Code
JavaScript
Works as a base for Node.js HTTP servers, serverless adapters, Cloudflare
Workers, and Google Cloud Functions. Keep the generic helpers, then replace
decide with your own routing logic.
Code
Cloudflare Workers
Paste the JavaScript helper functions above this worker export.
Code
Google Cloud Functions, Node.js
Use this with the JavaScript helper functions. Configure the function timeout
above the FunnelFlux timeoutMs, but keep your own external calls below the
FunnelFlux deadline.
Code
TypeScript
Code
Python
Works with Google Cloud Functions or Flask-style request objects.
Code
Go
Code
Operational Notes
- Recommended FunnelFlux
timeoutMs:1000to5000ms for simple functions. - Maximum FunnelFlux
timeoutMs:30000ms. - Be aware of external API client timeouts - use some appropriate values.
- For AI-generated functions, require the model to preserve field names exactly
and keep
body_json.decisionroute-compatible. - HMAC verification examples should be documented separately per platform. These templates do not hardcode secrets or assume every destination uses HMAC.