如何将NodeJS应用程序转换为war文件 [英] How to convert NodeJS application to war file

查看:79
本文介绍了如何将NodeJS应用程序转换为war文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个仪表板,其中React JS用于前端,Node JS用于后端.我已经为React JS项目构建了build文件夹,现在build文件夹位于Node JS应用程序内部.我的意思是,当我启动npm时,服务器开始在localhost 4000上运行,并且能够从build文件夹访问前端的所有文件,这意味着当我运行节点js服务器时项目正在运行.在本地系统上.问题是我想将此基于节点JS的应用程序转换为war文件,以便能够将其部署在apache服务器上.我对整个部署工作还是陌生的,因此可以欢迎任何帮助.

I have created a dashboard with React JS for front-end and Node JS for the backend. I have already built the build folder for React JS project, now the build folder is inside the Node JS application. What I mean by this is that when I give the npm start, the server starts running on localhost 4000 and able to access all the files of front-end from the build folder, it means the project is running when I run the node js server on local system. The problem is I want to convert this node JS based application into the war file so that I can able to deploy this on apache server. I am new to this whole deployment stuff so can any help will be welcomed.

推荐答案

node.js旨在创建您自己的http服务器,以运行您的JavaScript代码,还有一种方法可以安装Express模块​​来创建Express服务器以运行您的node.js应用程序,同样,通过创建服务器,可以使用许多不同的库来创建和运行Node js应用程序,tomcat表示Java http Web服务器,即与Java兼容的运行环境.

node.js meant to create your own http server, to run your javascript code, there is also way to install express module to create express server to run your node.js application, likewise there are lots of different libraries to create and run node js app on by creating server, tomcat means java http web server, thats java compatible running environment.

您已尝试创建构建,即您的 package.json

You have tried to create build, your package.json

"homepage":"http://localhost:8080/YOURAPPNAME",  
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build"    
  }

如果您正在使用Maven,则可以访问 pom.xml ,可以进行配置,为产品配置配置文件,使用 org.codehaus.mojo

If you are using maven, you got accesss to pom.xml, you can do config things, config profile for prod, use org.codehaus.mojo

<configuration>
  <environmentVariables>                                
    <PUBLIC_URL>http://frugalisminds.com/${project.artifactId}</PUBLIC_URL>
    <REACT_APP_ROUTER_BASE>/${project.artifactId}</REACT_APP_ROUTER_BASE>
  </environmentVariables>
</configuration>

您可以在app.jsx文件中设置 BrowserRouter

you can set your BrowserRouter in app.jsx file

<BrowserRouter basename={process.env.REACT_APP_ROUTER_BASE || ''}> 

您可能需要配置 web.xml 将err重定向到索引页面,

you might need to config web.xml redirect err to index page,

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
          http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
          version="2.4">
  <display-name>YOUR REACT SERVLET PROJECT NAME</display-name>
  <error-page>
    <error-code>404</error-code>
    <location>/index.html</location>
  </error-page>    
</web-app>

现在要创建 war mvn包,您可以探索有关 webpack-war-plugin

Now to create war do mvn package, you can explore about webpack-war-plugin

这篇关于如何将NodeJS应用程序转换为war文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆