Skip to main content

Rewrite Script

Called before the app sends a request to the real server and before the real server responds to the app, can be used to dynamically modify HTTP requests and responses.

  • The entry function for modifying requests is async function onRequest(context, url, request).
  • The entry function for modifying responses is async function onResponse(context, url, response).

Specific script examples can be found in the Script API Reference.

app ------ Call onRequest(context, url, request) --------> real server
app <----- Call onResponse(context, url, response) ------- real server

As shown in the diagram above, the onRequest method is synchronously called before the request is sent, with parameters (context, url, request), and the onResponse method is synchronously called before the response is returned to the app, with parameters (context, url, response).

Scripts can also load shared code with require('@libs/<key>'): built-in libs (@libs/base64, @libs/hex) are bundled with the app, so rewrite scripts can use them out of the box (see the require guide).

The JavaScript API used by Hodor is documented in the Script API Reference.