1
0
Fork 0
mirror of synced 2024-06-28 11:00:55 +12:00
budibase/packages/server/src/api/controllers/script.js

25 lines
527 B
JavaScript
Raw Normal View History

2021-03-27 03:56:34 +13:00
const fetch = require("node-fetch")
2021-03-26 00:17:04 +13:00
const vm = require("vm")
class ScriptExecutor {
2021-03-27 03:56:34 +13:00
constructor(body) {
this.script = new vm.Script(body.script)
this.context = vm.createContext(body.context)
this.context.fetch = fetch
2021-03-26 00:17:04 +13:00
}
execute() {
return this.script.runInContext(this.context)
2021-03-26 00:17:04 +13:00
}
}
2021-05-04 20:55:14 +12:00
exports.execute = async function (ctx) {
2021-03-27 03:56:34 +13:00
const executor = new ScriptExecutor(ctx.request.body)
2021-03-26 00:17:04 +13:00
ctx.body = executor.execute()
}
exports.save = async function(ctx) {
ctx.throw(501, "Not currently implemented")
2021-03-26 00:17:04 +13:00
}