- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我有一个 Electron 应用程序,我不仅需要为用户运行界面,还需要启动一个快速服务器,为通过网络连接的人提供文件。
如果我正常启动 electron 和 express 服务器,我一切正常,但我非常有信心我需要服务器在不同的线程中运行,以避免界面缓慢甚至服务器出现问题。
就此而言,我尝试使用 child_process.fork 运行我的 express 服务器,当我使用 npm start
时它可以工作,但是当我使用 electron-builder
创建时一个 .exe,安装的程序不会启动 express 服务器。
我尝试使用以下命令立即运行我的服务器:
require('child_process').fork('app/server/mainServer.js')
我尝试了几处更改,在文件前加上__dirname
、process.resourcesPath
,甚至硬编码生成的文件路径;更改 fork 选项以传递 cwd: __dirname
、detached: true
和 stdio: 'ignore'
;甚至尝试将 spawn
与 process.execPath
一起使用,它也可以与 npm start
一起使用,但在打包时不会(它会不断打开新实例我的应用程序,在你这样做之后似乎很明显呵呵)
注意:如果我不立即 fork 并要求服务器脚本,则使用 require('server/mainServer.js')
它适用于打包的应用程序,所以最喜欢的问题是不是 express 本身。
注意2:我有asar: false
来解决其他问题,所以这里不是问题解决者。
我建立了一个小 git 项目来展示我的问题:
https://github.com/victorivens05/electron-fork-error
我们将不胜感激。
最佳答案
在 Samuel Attard (https://github.com/MarshallOfSound) 的大力帮助下,我得以解决问题(他实际上为我解决了问题)
正如他所说:
the default electron app will launch the first file path provided to it
so `electron path/to/thing` will work
in a packaged state, that launch logic is not present
it will always run the app you have packaged regardless of the CLI args passed to it
you need to handle the argument manually yourself
and launch that JS file if it's passed in as the 1st argument
The first argument to fork simply calls `process.execPath` with the first
argument being the path provided afaik
The issue is that when packaged Electron apps don't automatically run the
path provided to them
they run the app that is packaged within them
换句话说。 fork
实际上是 spawn
使用 process.execPath
执行并将 fork 的第一个参数作为 spawn 的第二个参数传递。
在打包的应用程序中发生的情况是 process.execPath
不是 Electron ,而是打包的应用程序本身。因此,如果您尝试spawn
,应用程序将一遍又一遍地打开。
所以,Samuel 的建议是这样实现的:
if (process.argv[1] === '--start-server') {
require('./server/mainServer.js')
return
}
require('./local/mainLocal.js')
require('child_process').spawn(process.execPath, ['--start-server'])
这样,打包后的应用第一次执行时,process.argv[1]
为空,所以服务器不会启动。然后它将执行 Electron 部分(在我的例子中为 mainLocal)并重新启动应用程序,但这次传递 argv
。下次应用启动时,它会启动服务器并停止执行,因此应用不会再次打开,因为从未到达 spawn。
非常感谢塞缪尔。
关于node.js - child_process.fork 没有在打包的 Electron 应用程序内启动快速服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46554634/
我在使用 nuget 打包新包时遇到问题,因为当我通过命令行指定版本时,它会将它应用于包而不是依赖项。即 NuGet.exe pack myproject.csproj -Version 3.0.4.
考虑这个简短的例子: $a = pack("d",255); print length($a)."\n"; # Prints 8 $aa = pack("ddddd", 255,123,0,45,12
我有一个我想要的无符号整数数组(32 位) pack 成二进制流: my @n = (4,8,15,16,23,42); my $foo = join('', map(pack('I', $_), @
在我的工作中,我们必须在各种环境中部署应用程序。这是一个标准的 WAR 文件,需要一些配置,部署在 Tomcat 6 上。 有没有什么方法可以使用 Tomcat 创建一个“部署包”,以便您只需提取它并
我正在编写一个简单的数据包序列化程序,但我很难为我的数据包创建 header 。我正在创建一个缓冲区,然后尝试将前两项加载到缓冲区中。我运行 memcopy 但缓冲区中实际上没有任何内容,然后当我尝试
有人可以解释为什么当你有一个普通的小部件时,一行代码 A 可以工作 Entry(root, width=10).pack(side=LEFT,anchor=W) 但是当你给它命名或附加命令时,代码 A
我正在尝试使用this tutorial构建Python包。这是文件夹结构: testpackage\ testpackage\ __init__.py
我有 JFrame 和 GridBagLayout。用户可以调整此窗口的大小。此外,他还可以执行一些更改窗口大小的编辑操作。我使用 pack(); repaint(); 现在在这样的操作之后。但是,实
我有一个现实世界的问题,我认为需要某种优化,而不是对我关心的数据数组进行简单排序。我将在下面概述问题: 我有一个由不同设备组成的数据集,每个设备都有属性 A 和 B。A 和 B 彼此不依赖,但是,我想
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我必须将旧的“加密”数据从旧系统转换为适当的加密算法。我有这段代码: function unpackString($s,$l){ $tmp=unpack('c'.$l,$s);
我有两个发电机。第一个生成器有时需要调用第二个生成器并返回它从那里获得的值: def a(): for _b in b(): yield _b def b(): yie
首先:对不起,我知道有很多关于相对导入的问题,但我只是没有找到解决方案。如果可能的话,我想使用以下目录布局: myClass/ __init__.py test/ de
1 ambari + bigtop 构建大数据基础平台 1.1 参考: 1.2 参考 amabri bigtop 打包部署
所以 SimpleInjector 现在有一个包装 nuget,您可以使用它来隔离根组合的不同方面。 假设我在一个库中有一个可配置的组合根,它被应用程序中的多个项目重用。例如,在 Azure 解决方案
我想以易于分发的形式打包 Groovy CLI 应用程序,类似于 Java 对 JAR 所做的。我一直无法找到任何似乎能够做到这一点的东西。我发现了一些类似 this 的东西用于一次性脚本,但不能编译
目前 ZMI 管理“打包数据库”的功能有点粗糙。 1) 是否有可能为 Web UI 提供某种进度指示器?例如。一个告诉你还剩多少分钟/小时,至少给出某种估计 2) ZODB 打包如何影响站点的响应性?
我有一个看起来像这样的结构: struct vdata { static_assert(sizeof(uint8_t *) == 8L, "size of pointer must be 8");
我已经尝试打包/发布我的 Azure 项目有一段时间了(但没有成功)。我尝试过以下方法: 右键单击 -> 从 Visual Studio 打包/发布 (OutOfMemoryException) CS
我创建了一个 JavaScript 库,并将其打包为以下选定的选项:Shrink Variables和Base62 Encoded在这个网址:http://dean.edwards.name/pack
我是一名优秀的程序员,十分优秀!