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...]
Parameters | Description | Detailed Documentation |
---|---|---|
pattern | Expression to match request URLs | Match Pattern Documentation |
value | JS script to generate rules. Supports the following types: • Directory/File Path • Remote URL • Inline/Embedded/Values Content | Operation Instruction Documentation |
filters | Optional 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/Method | Description |
---|---|
url | Full request URL |
method | Request method (GET/POST, etc.) |
ip /clientIp | Client IP address |
headers | Request header object |
body | Request body (max 16KB) |
rules | Rule array, add new rules via push |
values | Temporary value storage object |
render(tpl,data) | Micro template rendering function |
getValue(key) | Get the value in Values |
parseUrl | Same as url.parse in Node.js |
parseQuery | Same as querystring.parse in Node.js |
Related Protocols
- Request-phase script rule: reqScript
- Request-phase batch rules: resRules
- Response-phase batch rules: resRules
- More complex customization requirements: Plugin development