You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functions-sandbox is the engine behind Backstage Functions and executes code in isolation (a sandbox). It could be used for both running code in production as well as testing the deployed functions (before they are deployed, hopefully).
$ npm install @globocom/functions-sandbox
Example of usage
constSandbox=require('backstage-functions-sandbox');constmySandbox=newSandbox({env: {MY_VAR: 'TRUE',// environment variable will be available on Backstage.env.MY_VAR},globalModules: ['path'],// put all available modules that will allow to importasyncTimeout: 10000,syncTimeout: 300,});constmyCode=mySandbox.compileCode('test.js',` async function main(req, res) { const result = req.body.x * req.body.y; const name = Backstage.env.MY_VAR; // you could call await here return { name, result }; }`);// express.Request compatibleconstreq={headers: {},query: {},body: {x: 10,y: 10}};mySandbox.runScript(myCode,req).then(({status, body})=>{console.info('Result:',status,body);},(err)=>{console.error('Error:',err);});