如何在此脚本节点 Js 中在虚拟机外运行脚本和代码字符串? [英] How to Runing scripts and code strings outside virtual machine in this script Node Js?

查看:63
本文介绍了如何在此脚本节点 Js 中在虚拟机外运行脚本和代码字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码是 Node-Red 核心节点库的一部分,您可以看到它在虚拟机vm"中执行脚本;Node.js 模块.

The following code is part of the Node-Red core node libraries, as you can see it executes scripts in a virtual machine "vm" Node Js module.

script on github node-red link

Any ideas on how the code should be written to execute script using the context of the Node Js environment instead of "vm" removing virtual machine usage?

Note: I am not interested in the problems related to executing insecure code, I just want it to do it outside the virtual machine to be able to use all the Node Js modules and their Globals without breaking Node-Red, because runInThisContext, get() and edit config.js is not the solution I want to remove the use of "vm".

Thanks for any idea

解决方案

Thanks to @knolleary

The solution is:

unsafe-function node for node-red node

unsafe-function node for node-red source

forked version of node-red

changes:

  • Replaced node "function" with node code "insecure function"
  • The node "vm" was created with the old node "function"
  • Added "text / x-red" script data help to new "function" node
  • Updated the data help of the script "text / x-red" to the new node "vm"
  • Added "require-from-string" dependency to node-red dependencies

这篇关于如何在此脚本节点 Js 中在虚拟机外运行脚本和代码字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆