Angular 2 application deployed on JBOSS 6.4 eap with java services as backend

Problem 1: Angular 2 application deployed on a JBOSS server but unable to load static content (js / css). The problem is that the website is hosted in its own context (localhost: 8080 / sample /) and the static resources refer to index.html as (link href = "css / index.css" rel = "stylesheet"), however, it does not get loaded as network calls are made on localhost: 8080 / css / index.css.

I need it to point to localhost: 8080 / sample / css / index.css

Problem 2: As an alternative, we tried to host the Angular application on tomcat, but the services should be hosted on jboss, we tried to implement the CROS filter ( https://amodernstory.com/2014/12/27/using-cors-headers-with- java-example / ), but the first request passes, but another request shows the pending status on the Chrome network tab.

+6
source share
2 answers

I have the same problem. To load it for static content, you need to set the base href inside index.html to "./". I found that "." also works. Then the application should load correctly, but you will encounter another problem: if you try to visit any of the application’s routes directly using the address bar, you will see “Not Found”. This seems to be due to JBoss being able to rewrite HTML5 URLs and redirect them to the index. I am trying to solve this problem using the information on this page: https://issues.jboss.org/browse/JDF-512 . I will let you know if I succeed.

+3
source

You can create index.prod.html with the correct links to "/sample/css/index.css". Then add the following to angular.json

"production": { "fileReplacements": [ { "replace": "src/index.html", "with": "src/index.prod.html" } 
0
source

Source: https://habr.com/ru/post/1264253/


All Articles