Skip to content

Scripting Support in Backend #580

@SoulKa

Description

@SoulKa

Is your feature request related to a problem? Please describe.
As a user, I would like to be able to execute scripts that modify the request.

Describe the solution you'd like

  • In the frontend, a new tab that allows writing JS code. There should be autocompletion for the trufos scripting API in the Monaco editor.
  • In the backend:
    • a scripting API that allows modification of the request (and body) before sending it
    • a separate JS file next to the request.json file
    • handling and execution of the JS file before sending the request
  • A scripting engine to run the script isolated from the actual app code
    • Use node:child_process.fork() to start a new node process with the user script as code
    • Inject the public calls to the app into the script (rufos.request object for request scripts and rufos.response for response scripts. Variable management, e.g. trufos.variables.set("myVar", "value")
  • The request should only be sent after the script ran successfully (if there's a request script)

Describe alternatives you've considered

  • A scripting engine to run the script isolated from the actual app code
    • Use node:child_process.fork() to start a runner script that translates calls to global variables and forwards them to the main process
    • Use node:vm to load the user script

This guarantees working globals and isolated script running. Might also speed up script running since the child process can live permanently and start multiple VMs (one per script) whenever it should run.

Additional context
This is a large feature. The exact subtasks need to be planned and written as issues.

Metadata

Metadata

Assignees

Labels

architectureArchitectural taskbackendBackend related task

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions