Modify
Scripting
Pro feature. Script rules need Akev Pro or its 14-day trial. Without a licence they stay saved and editable, but don't run.
A Script rule runs JavaScript (QuickJS, sandboxed) for matching requests. Define either or both hooks:
js
// Runs before the request is forwarded.
function onRequest(req) {
// req = { method, url, headers: { name: value | [values] }, body, bodyBase64 }
req.headers["x-debug"] = "1";
if (req.url.includes("/feature-flags")) {
// Returning a response object answers immediately without contacting the server.
return { status: 200, headers: { "content-type": "application/json" },
body: JSON.stringify({ newCheckout: true }) };
}
return req;
}
// Runs before the response is returned to the client.
function onResponse(req, res) {
// res = { status, statusMessage, headers, body, bodyBase64 }
if (res.headers["content-type"]?.includes("json")) {
const data = JSON.parse(res.body);
data.debug = { servedBy: "akev" };
res.body = JSON.stringify(data);
}
return res;
}- Bodies are decoded (gzip/brotli/zstd removed) before your script sees them and re-encoded
afterwards;
Content-Lengthis fixed automatically. console.log/warn/erroroutput is shown in the rule editor's test panel.- Each call is limited to 2 seconds of CPU time and 64 MB of memory.
- Scripts stack with other modifier rules and run in rule order.