Logic Lab (Hooks & Custom Logic)
The Logic Lab is Aerostack’s integrated development environment for the edge. It allows you to intercept any request, add custom business rules, and extend the platform’s core modules (Auth, E-commerce) without managing your own servers.
Core Concepts
In Aerostack, custom logic is implemented as Hooks. These are edge-native functions that run within our high-performance runtime, pre-wired with the Unified SDK.
1. Lifecycle Hooks
These hooks run at specific moments in the request/response lifecycle of pre-built modules.
- Example:
beforeSignup— Validate the user’s email domain before creating the account. - Example:
afterOrder— Trigger a loyalty point calculation after a successful purchase.
2. Custom API Endpoints
Create entirely new endpoints that leverage Aerostack’s infrastructure.
- Path:
https://<project>.aerostack.dev/api/v1/custom/<your-endpoint> - Use Case: Building a custom search index or a specialized reporting tool.
The Unified SDK in Hooks
Every hook receives a pre-authenticated sdk object. This is the exact same SDK you use in your project, ensuring a consistent developer experience across the board.
| Primitive | SDK Call | Why use it in Hooks? |
|---|---|---|
| Database | sdk.db.query() | Perform cross-table joins or custom data validation. |
| Cache | sdk.cache.set() | Store computed results at the edge for sub-millisecond lookups. |
| Queue | sdk.queue.enqueue() | Offload heavy tasks (like Slack notifications) to background workers. |
| AI | sdk.ai.chat() | Use LLMs to categorize user input or summarize data in real-time. |
Workflow: From Idea to Production
1. Develop
Use the built-in Monaco editor with full TypeScript support and AI assistance.
2. Test
Run dry-run tests with mock payloads directly in the browser or via CLI.
3. Deploy
Push your logic to the global network in under 1 second. No build pipelines required.
4. Monitor
Trace every execution through our built-in logs and performance dashboard.
Creating Your First Hook
- Navigate to Logic Lab in the Admin Panel.
- Select an event (e.g.,
auth.register.before). - Write your logic using the
sdk. - Test with a sample payload.
- Click Deploy.