Use cases
- Serve REST APIs and microservices straight from the edge
- Generate dynamic UIs and landing pages based on user interactions or geolocation
- Build AI-powered endpoints that process images, run chat completions, or generate embeddings
- Back a static frontend with contact forms, webhooks, and data submissions
- Call external APIs to send emails, transform data, or integrate with third-party services
The serve function
The serve function starts an HTTP server that listens for incoming requests and handles them using the provided handler function.
Function signature
Handler
The handler function receives a standard Request object and must return a Response orPromise<Response>.
Before cache execution
Preview Standalone scripts act as the origin for their Pull Zone, so by default they only execute when the cache is missed. If your Pull Zone is configured to execute scripts before cache, your script runs on every request, before the cache lookup.You can enable it in your Pull Zone under General > Origin >
Run script before cache, or directly in the script settings. Learn more
about before cache execution.