简体   繁体   English

如何将 package 和 Electron 应用程序与节点服务器一起使用

[英]How to package an Electron app together with a Node server

I have an electron app built using React.js and it relies on a local Node server running on parallel to the App.我有一个使用 React.js 构建的 electron 应用程序,它依赖于与应用程序并行运行的本地节点服务器。 How can I distribute both products in a single exe so that the Node server made separetely to the Electron app runs at the same time when executing the program?如何在一个 exe 中分发这两个产品,以便在执行程序时同时运行 Electron 应用程序单独制作的节点服务器?

You can just do it.你可以做到。 There is a Node process that kicks off the whole app, which you can start your server on.有一个启动整个应用程序的节点进程,您可以在其上启动服务器。 Then the client code is run by whatever you start the BrowserWindow on.然后客户端代码由你启动 BrowserWindow 的任何东西运行。 Then you can just make requests to localhost and your server should be able to pick them up.然后你可以向本地主机发出请求,你的服务器应该能够接收它们。

That said, there are some good reasons why you should strongly consider NOT using an actual HTTP server, but using inter-process communication (IPC) instead.也就是说,有一些充分的理由说明为什么您应该强烈考虑不使用实际的 HTTP 服务器,而是使用进程间通信 (IPC)。

  1. Security is an issue — you're starting a server on a client machine, and if your authentication has any flaws, you're opening up all your server endpoints to any other process on the client, or even other machines on the local.network.安全是一个问题——你在客户端机器上启动服务器,如果你的身份验证有任何缺陷,你就会向客户端上的任何其他进程开放所有服务器端点,甚至是 local.network 上的其他机器.

  2. Ease - IPC is well supported by Electron so it's simply easier to develop against.轻松 - IPC 得到 Electron 的良好支持,因此开发起来更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM