[英]nodejs - install production build of reactjs app on offline server, then set up to run as a service
I installed the following package globally using我使用全局安装了以下 package
npm install -g serve
on my development PC which has internet.在我有互联网的开发PC上。 It is currently the only package installed globally on my PC.
它是目前唯一安装在我的 PC 上的 package。
https://github.com/vercel/serve#readme https://github.com/vercel/serve#readme
After I compile and create a build folder, i run the following command to have the production version of code run using HTTPS.编译并创建构建文件夹后,我运行以下命令以使用 HTTPS 运行代码的生产版本。
serve -s build --listen 3000 --ssl-cert "/my/cert/server.crt" --ssl-key "/my/key/server.key"
Ok, so here comes the problem.好的,那么问题来了。 I have to run my code on a server that is not connected to the internet.
我必须在未连接到 Internet 的服务器上运行我的代码。 I've copied and moved the global node_modules folder over to the server and confirmed the permissions are the same between the server and dev pc.
我已将全局 node_modules 文件夹复制并移动到服务器上,并确认服务器和 dev pc 之间的权限相同。 I also confirmed that the package is seen as installed on the server by:
我还确认 package 被视为安装在服务器上:
npm list -g --depth=0
When I run the serve command above on the server, it has no clue what serve is.当我在服务器上运行上面的 serve 命令时,它不知道 serve 是什么。 CentOS complains about
CentOS 抱怨
bash: serve not found... bash:未找到服务...
So, I added an alias to the./~bashrc file on the server (which I also had to do on my dev pc and reloaded:因此,我在服务器上的 ./~bashrc 文件中添加了一个别名(我也必须在我的开发 PC 上这样做并重新加载:
vim ~/.bashrc
export PATH="$(npm bin -g):$PATH"
source ~/.bashrc
I found the export command in another SO post, and it worked on my dev pc, however linux still does not recognize the serve command.我在另一个 SO 帖子中找到了导出命令,它在我的开发电脑上运行,但是 linux 仍然无法识别服务命令。 I also need to know how to determine how to run this command from within a service, which means I also need the absolute path of the "serve" command.
我还需要知道如何确定如何从服务中运行此命令,这意味着我还需要“serve”命令的绝对路径。
I'm kinda stuck on this, since all the articles online only talk about how to run "npm start" as a service, which I can do for a development build of software with no issues.我有点坚持这一点,因为所有在线文章都只讨论如何将“npm start”作为服务运行,我可以毫无问题地进行软件开发构建。 I cannot find anything on how to set up a service for a production build.
我找不到有关如何为生产构建设置服务的任何信息。
I dont 100% need to use serve
, but my other coworker is using it for his project, which has internet access.我不需要 100% 使用
serve
,但我的另一个同事正在将它用于他的项目,该项目可以访问互联网。
I've even gone as far as trying to piece together the location of the main js file in the module:我什至试图拼凑模块中主 js 文件的位置:
/path/to/node_modules/serve/build/main.js -s build --listen 3000 --ssl-cert "/my/cert/server.crt" --ssl-key "/my/key/server.key"
This will allow me to start the service, but then I get all kinds of cross site scripting errors from my apache backend server.这将允许我启动服务,但随后我从 apache 后端服务器收到各种跨站点脚本错误。
Any help would, as always, be appreciated!一如既往,任何帮助将不胜感激! Thanks!
谢谢!
Disregard,漠视,
When I ran npm install -g serve
on the pc with internet, it created a soft link to the serve module.当我在有互联网的电脑上运行 npm
install -g serve
时,它创建了一个到服务模块的软链接。 I discovered this by running the following on my dev pc:我通过在我的开发电脑上运行以下命令发现了这一点:
which serve
I created that soft link on the offline server, and it appears to be working.我在离线服务器上创建了该软链接,它似乎正在工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.