How can I deploy a spring-boot webapp with angular 2 frontend (angular-cli build) to Tomcat?

Viewed 6849

I have a spring-boot web application and I build my frontend with angular-cli. I have set the output directory of my angular build in angular-cli.json to resources/static and I have configured the build script in package.json like this:

"scripts" : {"build": "ng build --base-href /mywebapp", ...}

In the application.properties of the spring-boot configuration I have set the server.contextPath to 'mywebapp'.

But if I build the angular application the included js files of the created index.html in resources/static does not contain the server context path 'mywebapp':

<script type="text/javascript" src="inline.bundle.js"></script>
<script type="text/javascript" src="polyfills.bundle.js"></script>

but I should look like this:

<script type="text/javascript" src="/mywebapp/inline.bundle.js"></script>
<script type="text/javascript" src="/mywebapp/polyfills.bundle.js"></script>

So if I deploy my spring-boot app to tomcat the built index.html is load but it cannot find the imported js files and tries to load the files under http://localhost:8080/ instead of http://localhost:8080/mywebapp/.

How can I deploy a spring-boot application with an angular-frontend to a tomcat server if I don't want to deploy it under the root directory?

2 Answers
Related