How to convert NodeJS application to war file

佐手、 提交于 2021-01-29 10:41:55

问题


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.


回答1:


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.

You have tried to create build, your package.json

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

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>

you can set your BrowserRouter in app.jsx file

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

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>

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



来源:https://stackoverflow.com/questions/56784590/how-to-convert-nodejs-application-to-war-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!