Inspired by:
https://github.com/jonashackt/spring-boot-vuejs
I am building a vue.js frontend and a spring-boot backend using the frontend-maven-plugin. My project has the following structure:
webapp
-> webapp-backend
-> webapp-frontend
During development running npm run serve works fine and I can access my frontend at:
But when I build the application (using the frontend-maven-plugin) and run it with:
mvn clean install
java -jar webapp-backend/target/webapp-backend-1.0.0-SNAPSHOT.jar
I just get a blank page:
Even though there are no errors from the java logs.
Are there some additional configuration I need to apply in e.g. the spring-boot backend to get it to redirect correctly to my frontend during a production build?
Below some more details:
webapp/webapp-backend/src/main/java/hello/GreetingController.java
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api")
public class GreetingController {
@RequestMapping(value = "/**/{[path:[^\\.]*}")
public String redirect() {
// Forward to home page so that route is preserved.
return "forward:/";
}
}
webapp-backend/pom.xml
<build>
<plugins>
...
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>Copy Vue.js frontend assets</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>src/main/resources/public</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>${project.parent.basedir}/webapp-frontend/dist</directory>
<includes>
<include>static/</include>
<include>index.html</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
webapp-backend/src/main/resources/public/index.html (non empty index.html file)
webapp/webapp-frontend/pom.xml
...
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>${frontend-maven-plugin.version}</version>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v10.0.0</nodeVersion>
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>npm run build</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...


webapp-backend/.... It seems to me you don't have any webapp-backend folder ? And could you tell me what is the content of your application.properties ? and the content of your folder : backend/src/main/resources/public ? thankswebapp-backend/src/main/resources/publicfolder ?webapp-backend/src/main/resources/public/index.html