请选择
Edge Developer Platform
  • Edge Functions
    • Overview
    • Getting Started
    • Operation Guide
      • Function Management
      • Function Trigger
    • Runtime APIs
      • addEventListener
      • Cache
      • Cookies
      • Encoding
      • Fetch
      • FetchEvent
      • Headers
      • Request
      • Response
      • Streams
        • ReadableStream
        • ReadableStreamBYOBReader
        • ReadableStreamDefaultReader
        • TransformStream
        • WritableStream
        • WritableStreamDefaultWriter
      • Web Crypto
      • Web standards
      • Images
        • ImageProperties
    • Sample Functions
      • Returning an HTML Page
      • Returning a JSON Object
      • Fetch Remote Resources
      • Authenticating a Request Header
      • Modifying a Response Header
      • Performing an A/B Test
      • Setting Cookies
      • Performing Redirect Based on the Request Location
      • Using the Cache API
      • Caching POST Requests
      • Responding in Streaming Mode
      • Merging Resources and Responding in Streaming Mode
      • Protecting Data from Tampering
      • Rewriting a m3u8 File and Configuring Authentication
      • Adaptive Image Resize
      • Image Adaptive WebP
      • Customize Referer restriction rules
      • Remote Authentication
      • HMAC Digital Signature
      • Naming a Downloaded File
      • Obtaining Client IP Address
    • Best Practices
      • Adaptive Image Format Conversion via Edge Functions

Function Trigger

Scenarios

This document guides you how to manage function triggering rules.
Add, delete, modify and search for a triggering rule.
Adjust the priority of the triggering rules by reordering them in the list. If the request URL matches multiple triggering rules, only the first hit rule is executed.

Directions

Creating a triggering rule

1. Log in to the EdgeOne console and click Site List in the left sidebar. In the site list, click the target site.
2. On the site details page, click Edge Functions > Function Management.
3. On the Function Trigger page, click the

icon to the right of the rule list.

Parameter description:
Site: The name of the current site is displayed by default.
Description: (Optional) It can contain up to 60 characters.
Condition: Specify the matching type, operator, and value as needed. For more information, see Rule Engine.
Execute function: Select a function from the drop-down list.
4. Click OK to complete the creation.

Editing the triggering rule

1. On the Function Trigger page, find the rule and click Edit.

2. In the Edit triggering rule dialog box, modify the parameters and click OK.


Searching for the triggering rule

On the Function Trigger page, click the

icon to the right of the rule list and enter a keyword of the rule ID in the search box to search for the triggering rule.


Deleting the triggering rule

1. On the Function Trigger page, click the

icon to the right of the rule list.
2. Find the rule to delete and click the

icon.

3. In the pop-up dialog box, click Confirm to delete.


Adjusting the priority of the triggering rule

1. On the Function Trigger page, click the

icon to the right of the rule list.
2. Find the rule. Click the

icon to move the rule up by one row or the

icon to move the rule down by one row. Then, click Save.
Reminder
If the request URL matches multiple triggering rules, such as Rules 01 and 02 in the following figure, only the triggering rule on the top will be executed. In this example, only Rule 01 will be executed.


Use Cases

The following section describes how to adjust the execution order of multiple triggering rules that match the request URL:
1. On the Function Management page, two functions with the same triggering rule are already created.

Code of the test1 function:
const html = `
<!DOCTYPE html>
<body>
<h1>The test 1, Hello World</h1>
<p>This markup was generated by a TencentCloud Edge Functions.</p>
<a href="https://cloud.tencent.com/product/teo">Tencent Cloud EdgeOne</a>
</body>
`;

async function handleRequest(request) {
return new Response(html, {
headers: {
'content-type': 'text/html; charset=UTF-8',
'x-edgefunctions-test': 'Welcome to use Edge Functions.',
},
});
}

addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});
Code of the test2 function:
const html = `
<!DOCTYPE html>
<body>
<h1>The test 2, Hello World</h1>
<p>This markup was generated by a TencentCloud Edge Functions.</p>
<a href="https://cloud.tencent.com/product/teo">Tencent Cloud EdgeOne</a>
</body>
`;

async function handleRequest(request) {
return new Response(html, {
headers: {
'content-type': 'text/html; charset=UTF-8',
'x-edgefunctions-test': 'Welcome to use Edge Functions.',
},
});
}

addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});
2. The triggering rules are displayed on the Function Trigger page, as shown in the following figure.





3. The triggering rule of the test1 function is listed in position 01, and that of the test2 function is in position 02, as shown in the following figure.


4. Enter the URL that contains the triggering rule in the address bar of a browser and press Enter. The following results are returned.


5. Click the

icon of the test2 function and then click Save.

6. The triggering rule of the test2 function is adjusted to position 01, and that of the test1 function is adjusted to position 02.
7. Enter the URL that contains the triggering rule in the address bar of a browser and press Enter. The response is as below: