Spring-boot-admin: Problems with resource resolution in SBA 2.1.0 having server.servlet.context-path set

Created on 5 Nov 2018  路  16Comments  路  Source: codecentric/spring-boot-admin

With having server.servlet.context-path set the resource resolution doesn't work property with SBA 2.1.0 wich results in a currupted login-page and a white page after login.

This problem only occurs when I set server.servlet.context-path. After deleting this property everythings works fine.

grafik

bug server-ui

Most helpful comment

I also have the same problem on staging environment as @dickerpulli .

With version 2.0.4 and defined a server.servlet.context-path=/demo-adminserver the generated base href was <base href="/demo-adminserver/" /> and all assets, css and js files were defined as for example <link="assets/css/sba-core.css" .. /> which will pull the resource from http://hostname/demo-adminserver/assets/css/sba-core.css. Now, the generated HTML template is <base href="" /> and all static resources start with /, which will pull the resources from http://hostname/assets/css/sba-core.css completely ignoring the context path.

All 16 comments

Just for local development (using npm run watch)?

No, also in staging environment.

I also have the same problem on staging environment as @dickerpulli .

With version 2.0.4 and defined a server.servlet.context-path=/demo-adminserver the generated base href was <base href="/demo-adminserver/" /> and all assets, css and js files were defined as for example <link="assets/css/sba-core.css" .. /> which will pull the resource from http://hostname/demo-adminserver/assets/css/sba-core.css. Now, the generated HTML template is <base href="" /> and all static resources start with /, which will pull the resources from http://hostname/assets/css/sba-core.css completely ignoring the context path.

Seeing the same behavior with the (equivalent?) configuration option spring.boot.admin.contextPath. The index page (and presumably API) resolve from the specified context path (i.e. /sba) but the UI loads static assets using host relative paths instead of including the context path, causing the blank white page and lots of errors on the console.

GET http://localhost:8080/assets/js/chunk-common.82a7af35.js net::ERR_ABORTED
sba:1 GET http://localhost:8080/assets/js/chunk-vendors.1df687d0.js net::ERR_ABORTED
sba:1 GET http://localhost:8080/assets/css/chunk-common.9808b72e.css net::ERR_ABORTED
sba:1 GET http://localhost:8080/assets/css/sba-core.360886fb.css net::ERR_ABORTED
sba:1 GET http://localhost:8080/assets/js/sba-core.7dfee25c.js net::ERR_ABORTED
sba:9 GET http://localhost:8080/assets/js/chunk-vendors.1df687d0.js net::ERR_ABORTED
sba:9 GET http://localhost:8080/assets/js/chunk-common.82a7af35.js net::ERR_ABORTED
sba:9 GET http://localhost:8080/assets/js/sba-core.7dfee25c.js net::ERR_ABORTED

馃憤

Some for me. This is critical, because usually one would deploy the admin ui to a tomcat webserver, where the servlet path is derived from the application filename.

So if you deploy a my-admin.war file, the location will be http://yourserver:8080/my-admin.
If only run locally with embedded tomcat, this can be simulated with setting server.servlet.context-path=/my-admin. Note that any server.* settings only apply to embedded tomcat!

In this case, as others mentioned already, spring-admin will still try to resolve the assets from localhost:8080/assets/... even if server.servlet.context-path is set!

Some for me. This is critical, because usually one would deploy the admin ui to a tomcat webserver, where the servlet path is derived from the application filename

I've currently very limited time to do a fix. You can stick to the 2.0.x server until then - the api for sba-client/-server is up- and downwards compatible

Not sure about GP. For us, upgrading was important because the 2.0.4 client wasn't playing nice in a Spring Boot 2.1.0 application. That said, I never did much testing with 2.1.0 client and 2.0.4 server. Sounds like that would be a good option to look at.

I can confirm the 2.1.0 client works with 2.0.4 server. thanks!

The fix in 2.1.1 is not working on my side. With the following configuration:

image

The base href is generated as followed:

image

Client and server have been updated to v2.1.1

@dotpanic Could you post a project to reproduce? A quick test (using cli parameters did work for me)

I'm sorry, the previous error was on my side (wrong docker container deployment).

The href is now filled with a base URL:

<base href="http://xxx.com/sba/">

But I now get some Mixed Content errors in browser:

image

The main page is served via HTTPS and so the base href should be set to:

<base href="https://xxx.com/sba/">

I can't understand if it's a Spring Boot or Spring Boot Admin issue.

Here is my server configuration;

server:
  port: 4040
spring:
  security:
    user:
      name: admin
      password: secret
  output:
    ansi:
      enabled: never
  boot:
    admin:
      context-path: /sba

# Spring Actuator
management:
  server:
    port: 9002
    address: localhost
  endpoints:
    web:
      exposure:
        include: "*"
      base-path: /sba/actuator
    enabled: true
    logfile:
      external-file: log/current-instance.log
    health:
      show-details: always

My SBA is served behind a reverse proxy, nginx being in charge of SSL implementation:

Browser ---https---> nginx ---http---> SBA

@dotpanic when running behind a proxy make sure the forward headers are set and taken into account. See https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-use-tomcat-behind-a-proxy-server
This should fix the wrong scheme in the URL

@joshiste setting server.use-forward-headers to true did the trick! Thank you! :)

Unfortunately, its not possible to set a relative path such as <base href="/sba/"> anymore. Behind a proxy without forward headers, this approach is not working.

Was this page helpful?
0 / 5 - 0 ratings