2017-06-27 92 views
0

問題陳述:我有兩個部分的應用程序。 前端和後端。前端使用React構建,其中使用Node.js,後端是maven web應用程序,前端和後端之間的通信使用REST完成。 我的應用程序正在兩臺服務器上運行。前端運行在Node.js後端運行在tomcat上。 我想要的是部署在同一臺服務器上的兩部分。如何在Tomcat中部署React應用程序?

我該怎麼做?

我試過了。

第一種方法:我試過使用maven插件。在pom.xml

<plugin> 
 
    <groupId>org.codehaus.mojo</groupId> 
 
    <artifactId>exec-maven-plugin</artifactId> 
 
    <executions> 
 
    <execution> 
 
     <id>exec-npm-install</id> 
 
     <phase>compile</phase> 
 
     <configuration> 
 
     <executable>npm</executable> 
 
     <arguments> 
 
      <argument>--prefix</argument> 
 
      <argument>${basedir}/src/main/webapp/ui</argument> 
 
      <argument>install</argument> 
 
      <argument>${basedir}/src/main/webapp/ui</argument> 
 
     </arguments> 
 
     </configuration> 
 
     <goals> 
 
     <goal>exec</goal> 
 
     </goals> 
 
    </execution> 
 
    <execution> 
 
     <id>exec-webpack</id> 
 
     <phase>compile</phase> 
 
     <configuration> 
 
     <executable>npm</executable> 
 
     <arguments> 
 
      <argument>--prefix</argument> 
 
      <argument>${basedir}/src/main/webapp/ui</argument> 
 
      <argument>run</argument> 
 
      <argument>build</argument> 
 
     </arguments> 
 
     </configuration> 
 
     <goals> 
 
     <goal>exec</goal> 
 
     </goals> 
 
    </execution> 
 
    </executions> 
 
</plugin>

加在後端的前端應用程序文件夾中,web應用程序的文件夾添加波紋管插件。 但這種方法的問題是,當我做mvn install所有node module下載和項目的大小變得非常大(700MB),因爲節點模塊。 這不是渴望。

我該怎麼做?

回答

0

Node.js本身就是一個服務器,不能由tomcat來處理。您必須並排安裝兩個服務器應用程序(前端在節點&後端在tomcat上)。由於你的前端文件不會被tomcat提供,所以你不應該在tomcat文件夾中安裝它們並且保持它們分離(儘管如此,你仍然可以使用maven來安裝它們)。

node.js服務器需要依賴文件(node_module文件夾),您無法擺脫它。

也涵蓋在Can node js be run within tomcat server

相關問題