Skip to content

resScript

Dynamically generate rules during the response phase using JavaScript to implement complex request processing logic. The script can access request context information and dynamically generate matching rules.

Rule Syntax

txt
pattern resScript://value [filters...]
ParametersDescriptionDetailed Documentation
patternExpression to match request URLsMatch Pattern Documentation
valueJS script to generate rules. Supports the following types:
• Directory/File Path
• Remote URL
• Inline/Embedded/Values Content
Operation Instruction Documentation
filtersOptional filters. Supports matching:
• Request URL/Method/Header/Content
• Response Status Code/Header
Filter Documentation

Configuration Example

txt
``` test.js
if (method === 'GET') {
    rules.push('* resType://text');
    rules.push('* file://(<div>GET-Request</div>)');
} else {
    rules.push('* resStatus://403');
}
```
www.example.com/path resScript://{test.js}

Accessing https://www.example.com/path/to does not execute * file://(<div>hello<div>) (because the rules generated by resScript are executed during the response phase).

Available Global Variables

Variable/MethodDescription
urlFull request URL
methodRequest method (GET/POST, etc.)
ip/clientIpClient IP address
headersRequest header object
bodyRequest body (max 16KB)
rulesRule array, add new rules via push
valuesTemporary value storage object
render(tpl,data)Micro template rendering function
getValue(key)Get the value in Values
parseUrlSame as url.parse in Node.js
parseQuerySame as querystring.parse in Node.js
  1. Request-phase script rule: reqScript
  2. Request-phase batch rules: resRules
  3. Response-phase batch rules: resRules
  4. More complex customization requirements: Plugin development