Deploy/run:本地 Express 网络服务器和本地客户端 angular 向该本地网络服务器发送 ajax 请求的应用程序

Deploy/run: local Express web-server and local client-side angular app that sends ajax requests to this local web-server

我有:

  1. 一个基于node express的网络服务器应该运行只在用户的本地机器上
  2. angular 客户端应用程序,它向本地 Web 服务器发送 GET Http 请求以获取 JSON 中的数据并将其显示在浏览器上

在我的开发环境中,我按如下方式启动:

  1. npm run dev(在 Express Web 服务器的目录中)。它产生:"Express server listening on port 7000" 并准备好接收请求
  2. npm start(在客户端应用程序的目录中)。这将在浏览器中启动客户端应用程序。然后我可以键入、单击按钮并获取显示的数据(来自网络服务器)。

我想以方便的方式向最终用户提供此系统:

  1. 目标环境是Windows。理想情况下,他们应该 运行 单个安装(例如从 .msi 文件)。
  2. 安装完成后,他们应该能够使用单个命令启动系统(网络服务器和客户端应用程序)。
  3. 最终用户不应该对节点、npm、..等一无所知,他们也不应该知道这两个组件的主目录——事实上,他们甚至可能不知道本地 express web-服务器正在使用中。

重要的不仅是安装方便,而且能够通过一个用户命令启动两个系统组件。当用户关闭客户端应用程序时,理想情况下 express web-server 也应该关闭。

我玩过 electron.js, but it seems it will not deploy and start the express server that is needed by the electron application. Also read about nw.js 但没有看到任何与我的场景相似的例子。

我知道也许吧???我可以将服务器端实现为电子渲染器进程之一,而不是 HTTP,使用进程间通信 (IPC) 与涉及主进程的客户端应用程序(另一个渲染器进程)通信。但是,这将需要对现有系统进行大量改造,这将需要大量时间并且目前无法负担得起。

部署和使用场景(上面的 1、2、3)是否可行?用于实现此类部署和执行场景的最佳工具是什么?

您能否提供任何此类实施的参考资料? And/or 理想情况下 small/complete 代码示例?

是的,你可以做到。你可以在生产环境中同时打包 electron app 和 express server。在开发中,您需要开发 express 应用程序并使用 nodejs child-process module. Here you can use exec command or spawn command 执行它(我更喜欢 exec,易于使用)。您可以从电子 main 流程开始快递流程。等待快速服务器设置,然后继续使用该应用程序。

对于木偶师,我建议你看看this github thread . They are saying to execute puppeteer on the main process and communicate the main and renderer processes by electron IPC

对于构建 windows 安装程序,我认为最好使用带有签名证书的 electron-builder and generate a nsis installer