3

I have three web application microservices and one gateway that include the UI. So, what i want to do is to change the app's that every microservice has his own UI and the gateway should make server side includes. Im using Thymeleaf as template engine and do the includes like this:

<div th:replace="http://localhost:8080/#/organizations"></div>

My Problem is that the CSS and JS files are not Included from the original localhost:8080 server rather from the server with includes the content localhost:9090.

This is how i include the JS and CSS files at *:8080:

<script th:src="@{webjars/jquery/$jquery.version$/jquery.min.js}"</script>

Hope you understand my problem and someone can help...

Markus Streicher
  • 133
  • 1
  • 1
  • 10
  • Could you post more code? Post the `organizations` panel code. I think the trouble occurs because `script` definition outside the `organizations` panel. Try to include it strict to this panel. ...Or you don't have access to the microservices source code? – sanluck Mar 02 '16 at 10:18
  • the organization source is just a normal html makup like `
    This is a test
    ` and there are the includes from css and javascript files like in my question
    – Markus Streicher Mar 02 '16 at 10:32
  • I mean they are not included into the server answer on request `http://localhost:8080/#/organizations`. Or they are? – sanluck Mar 02 '16 at 10:37
  • they are included on request. you mean in the organizations? yes like this` – Markus Streicher Mar 02 '16 at 10:48
  • Maybe they overrided by other scripts on the aggregator's side? Did you have any scripts over `organizations` inclusion? Other Jquery import? – sanluck Mar 02 '16 at 10:51
  • I think without source code of organizations panel and source of the page from browser it's difficult to suppose something. – sanluck Mar 02 '16 at 10:52
  • here is the project witch should include the file https://github.com/CPGFinanceSystems/spring-ssi and here is the file https://github.com/mstreicher/test – Markus Streicher Mar 02 '16 at 11:05

2 Answers2

4

This ${#httpServletRequest.requestURL} did the trick...

<link th:href="@{__${#httpServletRequest.requestURL}__webjars/bootstrap/?{bootstrap.version}/css/bootstrap.min.css}" rel="stylesheet" />

now all works fine.

Markus Streicher
  • 133
  • 1
  • 1
  • 10
0

I think you can't realize the behaviour you expect if you will use resources from localhost. Your test page can access local resources for context 9090, e.g. when it trying to request for example <script th:src="@{webjars/angularjs/$angularjs.version$/angular.min.js}"></script> from 9090 request goes to 9090 but resources on 8080. It will work if you will use static resources from CDN (from internet).

Maybe this article will be helpful for you.

sanluck
  • 1,544
  • 1
  • 12
  • 22