• Product Introduction
  • Quick Start
    • Importing a Git Repository
    • Starting From a Template
    • Direct Upload
  • Framework Guide
    • Frontends
    • Backends
    • Full-stack
      • Next.js
  • Project Guide
    • Project Management
    • edgeone.json
    • Configuring Cache
    • Error Codes
  • Build Guide
  • Deployment Guide
    • Overview
    • Create Deploys
    • Manage Deploys
    • Deploy Button
    • Use Github Actions
    • Using CNB Plugin
    • Using IDE Plug-In
    • Using CodeBuddy IDE
  • Domain Management
    • Overview
    • Custom Domain
    • Configuring an HTTPS Certificate
    • How to Configure a DNS CNAME Record
  • Pages Functions
    • Overview
    • Edge Functions
    • Node Functions
  • Log Analysis
  • KV Storage
  • Edge AI
  • API Token
  • EdgeOne CLI
  • Pages MCP
  • Integration Guide
    • AI
      • Dialogue Large Models Integration
      • Large Models for Images Integration
    • Database
      • Supabase Integration
      • Pages KV Integration
    • Ecommerce
      • Shopify Integration
      • WooCommerce Integration
    • Payment
      • Stripe Integration
      • Integrating Paddle
    • CMS
      • WordPress Integration
      • Contentful Integration
      • Sanity Integration
    • Authentication
      • Supabase Integration
      • Clerk Integration
  • Best Practices
    • Using General Large Model to Quickly Build AI Application
    • Use the Deepseek-R1 model to quickly build a conversational AI site
    • Building an Ecommerce Platform with WordPress + WooCommerce and GatsbyJS
    • Building a SaaS Site Using Supabase and Stripe
    • Building a Company Brand Site Quickly
    • How to Quickly Build a Blog Site
  • Migration Guides
    • Migrating from Vercel to EdgeOne Pages
    • Migrating from Cloudflare Pages to EdgeOne Pages
    • Migrating from Netlify to EdgeOne Pages
  • Troubleshooting
  • FAQs
  • Contact Us
  • Release Notes

Edge Functions

Overview

Edge Functions provides a Serverless code execution environment on EdgeOne Edge nodes. You just need to write business function code and set trigger rules, without the need to configure and manage server infrastructure, to run code securely and with elastic scaling on Edge nodes close to users.






Strengths

Distributed deployment
EdgeOne has over 3,200 edge nodes, and edge functions run on edge nodes via distributed deployment.

Ultra-low latency
Client requests are automatically scheduled to the edge node closest to your users. If a cache hit triggers the edge function, the request is processed and the response result is sent to the client, significantly reducing access latency.

Elastic Scale-out
Edge functions can route client requests from closest to farthest based on sudden increases in request volume, processing them on edge nodes with sufficient computational resources. You don't need to worry about spikes occur.

Serverless Architecture
You no longer need to care about or maintain the memory, CPU, network, and other infrastructure resources of underlying servers, freeing up effort to focus on developing business code.



Quick Start

Create hello.ts under the ./edge-functions directory and use the following example code to create your first Edge Functions:
export default function onRequest(context) {
return new Response('Hello from Edge Functions!');
}


Function Debugging

1. Install EdgeOne CLI: npm install -g edgeone
2. Local development: Under the Pages code project, execute edgeone pages dev to start the local service and perform function debugging.
3. Function release: Push code to the remote repository for auto-build function release.
For more ways to use EdgeOne CLI, see Documentation.



Routing

Edge Functions generates access routes based on the /edge-functions directory structure. You may create subdirectories at any level under the /edge-functions directory in the project repository. See the example below.
...
edge-functions
├── index.js
├── hello-pages.js
├── helloworld.js
├── api
├── users
├── list.js
├── geo.js
├── [id].js
├── visit
├── index.js
├── [[default]].js
...
The above directory file structure will generate the following routes after EdgeOne Pages platform construction. These routes map Pages URLs to /edge-functions files. When a client accesses the URL, it will trigger the corresponding file code to run:
File path
Routing
/edge-functions/index.js
example.com/
/edge-functions/hello-pages.js
example.com/hello-pages
/edge-functions/helloworld.js
example.com/helloworld
/edge-functions/api/users/list.js
example.com/api/users/list
/edge-functions/api/users/geo.js
example.com/api/users/geo
/edge-functions/api/users/[id].js
example.com/api/users/1024
/edge-functions/api/visit/index.js
example.com/api/visit
/edge-functions/api/[[default]].js
example.com/api/books/list
example.com/api/books/1024
example.com/api/...
Note:
The trailing slash / is optional. /hello-pages and /hello-pages/ will be routed to /edge-functions/hello-pages.js.
If no Edge Functions route is matched, client requests will be routed to the static resource of Pages.
- Routes are case-sensitive. /helloworld will be routed to /edge-functions/helloworld.js and cannot be routed to /edge-functions/HelloWorld.js.

Dynamic routing
Edge Functions support dynamic routing. In the above example, the first-level dynamic path is /edge-functions/api/users/[id].js, and the multi-level dynamic path is /edge-functions/api/[[default]].js. See the following usage:
File path
Routing
Match
/edge-functions/api/users/[id].js
example.com/api/users/1024
Yes
example.com/api/users/vip/1024
No
example.com/api/vip/1024
No
/edge-functions/api/[[default]].js
example.com/api/books/list
Yes
example.com/api/1024
Yes
example.com/v2/vip/1024
No


Function Handlers

Functions Handlers can create custom request handlers for Pages and define RESTful APIs to implement full-stack applications. Supported Handler methods:
Handlers method
Description
onRequest(context: EventContext): Response | Promise<Response>
Match HTTP Methods
(GET, POST, PATCH, PUT, DELETE, HEAD, OPTIONS)
onRequestGet(context: EventContext): Response | Promise<Response>
Match HTTP Methods (GET)
onRequestPost(context: EventContext): Response | Promise<Response>
Match HTTP Methods (POST)
onRequestPatch(context: EventContext): Response | Promise<Response>
Match HTTP Methods (PATCH)
onRequestPut(context: EventContext): Response | Promise<Response>
Match HTTP Methods (PUT)
onRequestDelete(context: EventContext): Response | Promise<Response>
Match HTTP Methods (DELETE)
onRequestHead(context: EventContext): Response | Promise<Response>
Match HTTP Methods (HEAD)
onRequestOptions(context: EventContext): Response | Promise<Response>
Match HTTP Methods (OPTIONS)

EventContext object description
The context is an object passed to Function Handlers methods, containing the following properties:
request: client request object Request
params: dynamic routing /edge-functions/api/users/[id].js parameter value
export function onRequestGet(context) {
return new Response(`User id is ${context.params.id}`);
}
env: Pages environment variables
waitUntil: (task: Promise<any>): void; Used to notify the edge function to wait for the Promise to complete, extending the event handling lifecycle.


Runtime APIs

Edge Functions are based on Edge Functions, providing a Serverless code execution environment on EdgeOne Edge nodes. They support ES6 syntax and standard Web Service Worker API. Most Runtime APIs can be found in Edge function usage. See the description below:
API
Description
Cache is designed based on the Web APIs standard Cache API. The Functions runtime environment will inject a global Cache object, which provides a group of Cache operation APIs.
Cookies provide a group of cookie operation APIs.
Designed based on the Web APIs standard TextEncoder and TextDecoder, it implements an encoder and decoder.
Designed based on the Web APIs standard Fetch API. The function runtime can use fetch to trigger async requests and retrieve remote resources.
Headers are designed based on the Web APIs standard Headers. Applicable to HTTP request and response header operations.
Request represents the HTTP request object, designed based on the Web APIs standard Request.
Response represents the HTTP response, designed based on the Web APIs standard Response.
ReadableStream, also known as readable stream, is designed based on the Web APIs standard ReadableStream.
Web Crypto API is designed based on the Web APIs standard Web Crypto API. It provides a group of common encryption APIs. Compared with pure JavaScript encryption APIs, Web Crypto API delivers higher performance.
Edge Function is a Serverless code execution environment designed and implemented based on the V8 JavaScript engine, providing the following standardized Web APIs.
Note:
Currently, fetch cannot be used to access EdgeOne node cache or origin in the EdgeOne CLI debugging environment.
Use context.request.eo to get client GEO info.
Edge Functions does not support addEventListener. Listen to client requests based on Function Handlers.


Use Limits

Content
Limit
Description
Code package size
5 MB
Single function code package size supports up to 5 MB
Request body size
1 MB
Client request body supports up to 1 MB
CPU time
200 ms
CPU time slice allocated for single execution of a function, excluding I/O wait time
Development Language
JavaScript
Currently only support JavaScript, ES2023+


Sample Template


Retrieve user access geolocation:

Use KV to record page views:
For detailed information on how to use KV storage, see KV storage.

Connect to supabase third-party database: