All Products
Search
Document Center

Edge Security Acceleration:Create an application from a function template

Last Updated:Dec 04, 2025

ESA points of presence (POPs) provide a serverless environment to run your code. You can write your code and configure trigger rules without needing to configure servers or manage infrastructure. Your code can scale elastically and run securely on POPs that are close to your users. This significantly reduces O&M costs and improves response speed.

Step 1: Create a function

  1. Log on to the ESA console. In the navigation pane on the left, choose Edge Computing > Functions and Pages.

  2. On the Functions and Pages page, click Create.

  3. Click the Function Templates tab, select a function template as needed, and then click Next.

    image

  4. Enter a Routine Name and Description, preview the code details, and click Submit.

    image

  5. After the system build is complete, a public domain name is generated for you to access the function. You can use this domain name to directly access and preview the result. To bind a custom domain name, see How to bind a custom domain name.imageimage

Step 2: Develop and test the function

You can modify the function code and test it locally as needed. After that, deploy the code to the test environment. Continuously monitor its running status and performance to ensure stability and correctness.

  1. Click Associate Domain Name and then select the Code tab. You can develop the function using JavaScript ES6 syntax.

    image

    image

  2. ESA provides a staging environment to the right of the code development tool in the console. After you finish developing the code, click Save. In the toolbar on the right, construct the HTTP request method, request header, and request body. After the construction is complete, click the Request button. The console directly returns the response after the request is processed by the function.

  3. After testing the code, click Generate Version.

  4. Select the Deploy tab and click Release. In the dialog box that appears, select Staging Environment to publish the version. The function will take effect on the edge test POPs. You can directly bind a Host to send requests from a real client and view the results on the client.

    image

Step 3: Publish the official version

After the function runs stably in the test environment and passes verification, you can publish the function code to the production environment.

  1. Select the Deploy tab and click Released Versions .

  2. Click Production Environment, select the version to be published, and then click Release. All POPs in the production environment will then deploy this version of the function code.

    image

How to bind a custom domain name

You can bind a domain name to a function to forward all traffic from the specified domain name to that function. For example, if you bind er.example.com to a function, all requests to that domain name are handled by the function. You can also configure URL path rules through function routing to forward traffic from specific paths under a domain name to the function. For example, you can route requests for er.example.com/test/path/ to the function to achieve flexible and fine-grained traffic rerouting.

Prerequisites

Binding steps

  1. On the Functions and Pages page, select the function that you created.image

  2. Select the Domain Names tab. You can forward traffic from the domain name to the function by adding a domain name or a routing rule.

    Add a domain name

    After you bind a domain name to the function, you can directly use that domain name to access the function.

    For example, if you have added the site example.com in ESA, you can bind the domain name as er.example.com. Then, requests to er.example.com, er.example.com/user, and er.example.com/login will be forwarded to the edge function.

    1. In the Custom Domains section, click Add Domain Name.

    2. Enter the domain name and click OK.

      image

    Note

    For domain names connected using NS records: After you bind the domain name, the system automatically adds a DNS record for the function.

    For domain names connected using a CNAME record: After you bind the domain name, a CNAME value is automatically generated. You must manually add a CNAME record with your domain name resolution service provider for the current site.

    Add a route

    The routing feature lets you map specific URLs to a function. When a request matches a configured URL, the function processes the request. Otherwise, the request continues through the accelerated back-to-origin ESA flow. As shown in the following figure, if you configure a routing rule of example.com/a* for the example.com site, all path accesses that match the routing rule, such as /a, /a1, and /a2, are processed by the function. Other path accesses that do not match the routing rule, such as /b, /c, and /d, continue to follow the accelerated back-to-origin or caching flow.

    image
    1. In the Routes section, click Add Route.

    2. Enter a Route Name and select the target site from the Select Website list, for example, example.com.

    3. Select a Route Mode.

      Simple mode

      1. Enter a Route Name and select the target site.

      2. Select SImple Mode and enter the routing rule.

        image

      Custom mode

      1. Enter a Route Name and select the target site.

      2. Select Custom Mode.

      3. In the If requests match... section, set the request features to match. For more information about how to configure rules, see Rule expression components.

      4. Then, execute the edge function.

        image

      • Example 1: If you set the route to *.example.com/*, any request sent to http://www.example.com/ or http://example.com/ is forwarded to the function.

      • Example 2: If you set the route to example.com/a*, any request sent to http://example.com/a, http://example.com/a1, or http://example.com/api is forwarded to the function.

      • Example 3: If you set the route to www.example.com/api/*, any request sent to http://www.example.com/api/ and its subpaths, such as http://www.example.com/api/users or http://www.example.com/api/products/123, is forwarded to the function.

    4. Click OK.

    Note
    • If the route you enter is a domain name with a prefix, such as *.example.com or www.example.com, you must also manually add a record to the DNS records in ESA. Otherwise, access will fail.

    • If multiple function routes are configured, the system checks them from top to bottom. When a match is found, the system stops checking the remaining routes.

    Matching rules

    • A route configuration must include both the domain hostname and the path URI. Therefore, you cannot configure a routing rule that contains only a path URI, such as /path.

    • You can add a wildcard character (*) at the beginning or end of a route configuration to match more requests. The wildcard character * can match zero or more of any character. For example, example.com/* matches all requests to example.com.

    • Route configurations are case-sensitive. For example, example.com/a and example.com/A are two different routing rules.

    • You cannot configure a wildcard character (*) or parameters in the middle of a route. For example, formats such as example.com/*/path and example.com/path?param=1 are not allowed.

    • When an access request matches multiple route configurations, the rule that was configured earlier takes precedence.