In the DCDN console, you can create EdgeScript rules based on your EdgeScript code and publish them to the production environment to customize the management of DCDN products. This topic describes how to configure and use EdgeScript in the console.
Procedure

-
Log on to the DCDN console.
-
In the left navigation pane, click Domain Names.
-
On the Domain Names page, find the domain name that you want to manage and click Configure.
-
Click EdgeScript.
-
Add a rule in the staging environment.
-
On the Staging Environment tab, click Add Rule to configure an EdgeScript rule.
Note-
You can add only one EdgeScript rule for each domain name. If you need to add more rules, submit a ticket.
-
The staging environment supports only points of presence (POPs) in the Chinese mainland.

The following table describes the rule parameters.
Parameter
Required
Description
Script Name
Yes
The rule name. Can contain only letters, digits, and underscores (_).
Script Code
Yes
-
You can enter the rule code directly or click Use Code Template to select a template for a specific use case.
-
You can write the rule code based on your use case. For more information, see EdgeScript use case examples.
Priority
Yes
The rule priority. Valid values: 0 to 999. A larger value indicates a lower priority. Rules at different execution positions have independent priority settings.
Run Script At
Yes
The execution position of the rule. For details, see Execution position and priority.
Status
Yes
Enables or disables the rule.
Break
No
When enabled, stops subsequent rules in the same phase from running after this rule matches.
Extensions
No
Enables rule extensions. Currently, only the
_es_dbg=signaturefield is supported, which enables debug mode. -
-
Click Publish to Staging Environment.
-
-
Test the rule in the staging environment.
Test scripts in the staging environment before publishing them to production. To get the staging test IP address, resolve the domain name staging.myalicdn.com. Then, map this IP address to the accelerated domain name in your client's hosts file.
Add the mapping between the staging test IP address and the accelerated domain name to the hosts file. The path to the hosts file varies based on the operating system:
-
Windows: C:\Windows\System32\drivers\etc\hosts.
-
macOS: /etc/hosts.
-
-
After the test is complete, click Publish All Rules to Production Environment to publish the rules from the staging environment to the production environment.
ImportantPublishing rules to the production environment automatically clears them from the staging environment.

Roll back staging environment rules
To clear all configurations and reset the staging environment to its initial state, click Roll Back Scripts. In the dialog box that appears, click OK.

Modify a script configuration

To modify a rule in the production environment, do not edit it directly. Instead, copy it to the staging environment, make and test your changes, and then publish the updated rule back to production.
-
Click Roll Back Scripts to reset the staging environment. This prevents interference from previous configurations.
-
Click Copy Rules from Production Environment to copy the rules from the production environment to the staging environment. This avoids potential inconsistencies from manual copying.

-
In the staging environment, add, modify, or delete rules.
-
Click Publish to Staging Environment. Then, test the rules in the staging environment. For more information, see the Test the rule in the staging environment step.
-
After testing, click Publish All Rules to Production Environment and verify that the rules work as expected in the production environment.
You can also manage EdgeScript by using the CLI. For details, see Use the CLI to manage EdgeScript.