Technology
This module provides server-side JavaScript execution capabilities for Project Forge applications using the Goja JavaScript runtime.
Features
- JavaScript Execution: Run ES5+ JavaScript files using the Goja interpreter
- Web-based Script Management: Create, edit, and execute scripts through a web UI at
/admin/scripting - Automatic Testing: Scripts can include example test cases that are automatically executed
- Filesystem Integration: Scripts are stored as
.jsfiles and managed through the filesystem module - Search Integration: Scripts are indexed and searchable within Project Forge applications
Installation
Add this module to your project configuration, by using the UI or editing project.json directly:
1 | |
Usage
Service Setup
Create a new scripting service in your application:
1 | |
Web Interface
Access the scripting interface at /admin/scripting to:
- List all available scripts
- View script content and execution results
- Create and edit scripts
- Run scripts and view output
- Test example functions automatically
JavaScript Environment
Each script runs in an isolated JavaScript VM
Example Testing
Scripts can include automated test examples that will be executed when viewing the script:
1 | |
The examples object maps function names to arrays of parameter sets. Each parameter set will be passed to the function and the results displayed in the web interface.
Script Management
Scripts are stored as .js files in the configured directory. The service provides methods to:
ListScripts()- Get all JavaScript filesLoadScript(path)- Load script contentSaveScript(path, content)- Save script to filesystemDeleteScript(path)- Remove script file
Error Handling
Scripts are executed in isolated VMs with comprehensive error handling: - Syntax errors are caught during script loading - Runtime errors are captured and displayed - VM isolation prevents scripts from affecting each other
API Endpoints
When included in a Project Forge application, the module provides these routes:
GET /admin/scripting- List all scriptsGET /admin/scripting/{path}- View specific script and run examplesPOST /admin/scripting/{path}- Execute script with custom parametersPUT /admin/scripting/{path}- Save script contentDELETE /admin/scripting/{path}- Delete script
Security Considerations
- Scripts can execute arbitrary JavaScript code
- No sandboxing beyond VM isolation is provided
- Scripts have access to all functions exposed to the JavaScript environment
- Only deploy in trusted environments where script execution is acceptable
- Consider network restrictions if scripts might make external calls
Source Code
- Repository: https://github.com/kyleu/projectforge/tree/main/module/scripting
- License: CC0 (Public Domain)
- Author: Kyle U (kyle@kyleu.com)