是否可以从网页运行Node脚本? [英] Is it possible to run a Node script from a web page?
问题描述
我现在要搜索几天,但找不到答案.我想执行以下操作:
I'am searching for days now but could not get an answer. I would like to do the following:
- 用户连接到editor.html(具有基本http身份验证的Apache2)
- 用户希望使用其用户/密码(与passwd相同)打开服务器上的文件(例如/home/user1/myfile.txt)
- Node.js脚本从上开始具有用户权限,用户可以编辑文件
Node脚本将通过websocket处理连接并读取/写入文件.
The Node Script will handle the connection via websockets and read/writes files.
我认为最大的问题是不可能从网页上在服务器上运行节点脚本...而且我不想涉及任何php/cgi脚本...仅Apache和Node.js/JS.
I think the biggest problem is that its not possible to run a node script on the server from a web page... and I don´t want to involve any php/cgi scripts... only Apache and Node.js / JS.
如果您知道这确实不可能的话,也请发表评论或回答...
Please also comment or answer if you know that it is really not possible...
谢谢!
柯达
工作流程应为以下内容:用户访问网页->输入其凭据(与passwd相同)-> node.js脚本以已登录用户的用户权限开始->以用户权限读取或写入文件
The workflow should be the following: User access webpage -> enters his credential (same as in passwd) -> node.js script gets started with the user rights of the logged in user -> files getting read or written with user rights
最大问题:谁启动了Node.js脚本?阿帕奇?怎么样?
Biggest Problem: who starts the Node.js script? Apache? How?
推荐答案
我不想成为这个人,但是...
I hate to be this person, but...
这不是节点的设计方式,而是设计为使用事件循环,我建议让节点为静态文件提供服务,也许使用apache作为代理,然后当有人请求某个页面时,执行所需的操作要做到这一点,如果您真的必须生成一个子进程,请使用 child_process.spawn
,关于用户的权限,我建议您仅传入一个代码,例如1 = admin,2 = user,3 = guest,子进程可以完成所需的工作.
That is not the way node is designed, it is designed to use the event loop, I would recommend having node serve the static files, maybe using apache as a proxy, then when someone requests a certain page, doing what ever needs to be done, if you really must spawn a child process, use child_process.spawn
, as for the rights of the user, I recommend just passing in a code, like 1=admin, 2=user, 3=guest, and the child process can do what is needs.
这篇关于是否可以从网页运行Node脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!