Skip to content

Commit 8f42d3e

Browse files
authored
fix: custom-uis do not work as expected (#2311)
* fix: custom-uis do not work as expected closes #2304, #2255, #2221, #2219 * add documentation * copy routes.txt file to target directory to include custom routes in HomepageForwardingFilter * remove console.log
1 parent 202a36a commit 8f42d3e

File tree

25 files changed

+1592
-14792
lines changed

25 files changed

+1592
-14792
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[[customizing-headers]]
2+
== Injecting Custom HTTP Headers ==
3+
4+
In case you need to inject custom HTTP headers into the requests made to the monitored application's actuator endpoints you can easily add a `HttpHeadersProvider`:
5+
6+
[source,java,indent=0]
7+
----
8+
include::{samples-dir}/spring-boot-admin-sample-servlet/src/main/java/de/codecentric/boot/admin/SpringBootAdminServletApplication.java[tags=customization-http-headers-providers]
9+
----
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[[customizing-instance-filter]]
2+
== Intercepting Requests And Responses ==
3+
4+
You can intercept and modify requests and responses made to the monitored application's actuator endpoints by implementing the `InstanceExchangeFilterFunction` interface.
5+
This can be useful for auditing or adding some extra security checks.
6+
7+
[source,java,indent=0]
8+
----
9+
include::{samples-dir}/spring-boot-admin-sample-servlet/src/main/java/de/codecentric/boot/admin/SpringBootAdminServletApplication.java[tags=customization-instance-exchange-filter-function]
10+
----
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[[customizing-notifiers]]
2+
== Custom Notifiers ==
3+
4+
You can add your own Notifiers by adding Spring Beans which implement the `Notifier` interface, at best by extending
5+
`AbstractEventNotifier` or `AbstractStatusChangeNotifier`.
6+
7+
[source,java,indent=0]
8+
----
9+
include::{samples-dir}/spring-boot-admin-sample-servlet/src/main/java/de/codecentric/boot/admin/CustomNotifier.java[tags=customization-notifiers]
10+
----

spring-boot-admin-docs/src/site/asciidoc/_customizing.adoc renamed to spring-boot-admin-docs/src/site/asciidoc/customize_ui.adoc

Lines changed: 50 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,5 @@
1-
[[customizing]]
2-
== Customizing ==
3-
4-
[[customizing-notifiers]]
5-
=== Custom Notifiers ===
6-
7-
You can add your own Notifiers by adding Spring Beans which implement the `Notifier` interface, at best by extending
8-
`AbstractEventNotifier` or `AbstractStatusChangeNotifier`.
9-
10-
[source,java,indent=0]
11-
----
12-
include::{samples-dir}/spring-boot-admin-sample-servlet/src/main/java/de/codecentric/boot/admin/CustomNotifier.java[tags=customization-notifiers]
13-
----
14-
15-
[[customizing-headers]]
16-
=== Injecting Custom HTTP Headers ===
17-
18-
In case you need to inject custom HTTP headers into the requests made to the monitored application's actuator endpoints you can easily add a `HttpHeadersProvider`:
19-
20-
[source,java,indent=0]
21-
----
22-
include::{samples-dir}/spring-boot-admin-sample-servlet/src/main/java/de/codecentric/boot/admin/SpringBootAdminServletApplication.java[tags=customization-http-headers-providers]
23-
----
24-
25-
[[customizing-instance-filter]]
26-
=== Intercepting Requests And Responses ===
27-
28-
You can intercept and modify requests and responses made to the monitored application's actuator endpoints by implementing the `InstanceExchangeFilterFunction` interface.
29-
This can be useful for auditing or adding some extra security checks.
30-
31-
[source,java,indent=0]
32-
----
33-
include::{samples-dir}/spring-boot-admin-sample-servlet/src/main/java/de/codecentric/boot/admin/SpringBootAdminServletApplication.java[tags=customization-instance-exchange-filter-function]
34-
----
35-
361
[[customizing-external-views]]
37-
=== Linking / Embedding External Pages ===
2+
== Linking / Embedding External Pages ==
383

394
You can very simply add a link to external pages via configuration or even embed them (adding the `iframe=true`):
405

@@ -44,107 +9,115 @@ include::{samples-dir}/spring-boot-admin-sample-servlet/src/main/resources/appli
449
----
4510

4611
[[customizing-custom-views]]
47-
=== Custom Views ===
12+
== Custom Views ==
4813

49-
It is possible to add custom views to the ui. The views must be implemented as https://vuejs.org/[Vue.js] components.
14+
It is possible to add custom views to the ui.
15+
The views must be implemented as https://vuejs.org/[Vue.js] components.
5016

5117
The JavaScript-Bundle and CSS-Stylesheet must be placed on the classpath at `/META-INF/spring-boot-admin-server-ui/extensions/{name}/` so the server can pick them up.
5218
The {github-src}/spring-boot-admin-samples/spring-boot-admin-sample-custom-ui/[spring-boot-admin-sample-custom-ui] module contains a sample which has the necessary maven setup to build such a module.
5319

54-
The custom extension registers itself by calling `SBA.use()` and need to expose a `install()` function, which is called by the ui when setting up the routes.
55-
The `install()` function receives the following parameters in order to register views and/or callbacks:
56-
57-
* Object referencing the {github-src}/spring-boot-admin-server-ui/src/main/frontend/viewRegistry.js[viewRegistry]
20+
The custom extension registers itself by calling:
5821

59-
* Object referencing the {github-src}/spring-boot-admin-server-ui/src/main/frontend/store.js[applicationStore]
22+
[source,javascript]
23+
----
24+
include::{samples-dir}/spring-boot-admin-sample-custom-ui/src/index.js[tags=customization-ui-toplevel]
25+
----
6026

61-
* Object referencing the the global Vue[Vue]
27+
<1> Name of the view and the route.
28+
<2> Path in Vue router.
29+
<3> The imported custom component, which will be rendered on the route.
30+
<4> The handle for the custom view to be shown in the top navigation bar.
31+
<5> Order for the view.
32+
<6> Using `i18n.mergeLocaleMessage` allows to add custom translations.
6233

63-
* Object referencing the {github-src}/spring-boot-admin-server-ui/src/main/frontend/utils/axios.js[axios]
34+
Views in the top navigation bar are sorted by ascending order.
6435

65-
If new top level routes are added to the frontend, they also must be known to the backend. Add a `/META-INF/spring-boot-admin-server-ui/extensions/{name}/routes.txt` with all your new toplevel routes (one route per line).
36+
If new top level routes are added to the frontend, they also must be known to the backend.
37+
Add a `/META-INF/spring-boot-admin-server-ui/extensions/{name}/routes.txt` with all your new toplevel routes (one route per line).
6638

6739
[[customizing-custom-views-top-level]]
6840
==== Adding a Top-Level View ====
6941

7042
Here is a simple top level view just listing all registered applications:
7143
[source,html]
44+
7245
----
7346
include::{samples-dir}/spring-boot-admin-sample-custom-ui/src/custom.vue[lines=17..-1]
7447
----
75-
<1> If you define a `applications` prop the component will receive all registered applications.
7648

77-
TIP: There are some helpful methods on the application and instances object available. Have a look at {github-src}/spring-boot-admin-server-ui/src/main/frontend/services/application.js[application.js] and {github-src}/spring-boot-admin-server-ui/src/main/frontend/services/instance.js[instance.js]
49+
<1> By destructuring `applications` of `SBA.useApplicationStore()`, you have reactive access to registered applications.
50+
51+
TIP: There are some helpful methods on the application and instances object available.
52+
Have a look at {github-src}/spring-boot-admin-server-ui/src/main/frontend/services/application.js[application.js] and {github-src}/spring-boot-admin-server-ui/src/main/frontend/services/instance.js[instance.js]
7853

7954
And this is how you register the top-level view.
80-
[source,javascript]
81-
----
82-
include::{samples-dir}/spring-boot-admin-sample-custom-ui/src/index.js[tags=customization-ui-toplevel]
83-
----
84-
<1> Name of the view and the route to the view.
85-
<2> Path where the view will be accessible.
86-
<3> The imported custom component, which will be rendered on the route.
87-
<4> The label for the custom view to be shown in the top navigation bar.
88-
<5> Order for the view. Views in the top navigation bar are sorted by ascending order.
8955

9056
===== Example
57+
9158
[source,javascript]
9259
----
9360
include::{samples-dir}/spring-boot-admin-sample-custom-ui/src/index.js[tags=customization-ui-child]
9461
----
62+
9563
<1> References the name of the parent view.
9664
<2> Router path used to navigate to.
9765
<3> Define whether the path should be registered as child route in parent's route.
98-
When set to `true`, the parent component has to implement `<router-view>`
66+
When set to `true`, the parent component has to implement `<router-view>`
9967

10068
The `routes.txt` config with the added route:
10169
[source,text]
70+
10271
----
10372
include::{samples-dir}/spring-boot-admin-sample-custom-ui/src/routes.txt[]
10473
----
10574

10675
[[customizing-custom-views-instance]]
107-
==== Visualizing a Custom Endpoint ====
76+
=== Visualizing a Custom Endpoint ===
77+
10878
Here is a view to show a custom endpoint:
10979
[source,html]
80+
11081
----
11182
include::{samples-dir}/spring-boot-admin-sample-custom-ui/src/custom-endpoint.vue[lines=17..-1]
11283
----
84+
11385
<1> If you define a `instance` prop the component will receive the instance the view should be rendered for.
11486
<2> Each instance has a preconfigured https://github.com/axios/axios[axios] instance to access the endpoints with the correct path and headers.
11587

11688
Registering the instance view works like for the top-level view with some additional properties:
11789
[source,javascript]
90+
11891
----
11992
include::{samples-dir}/spring-boot-admin-sample-custom-ui/src/index.js[tags=customization-ui-endpoint]
12093
----
94+
12195
<1> The parent must be 'instances' in order to render the new custom view for a single instance.
12296
<2> You can group views by assigning them to a group.
12397
<3> If you add a `isEnabled` callback you can figure out dynamically if the view should be show for the particular instance.
124-
<4> Register custom i18n translations
12598

12699
NOTE: You can override default views by putting the same group and name as the one you want to override.
127100

128101
=== Customizing Header Logo and Title ===
102+
129103
You can set custom information in the header (i.e. displaying staging information or company name) by using following configuration properties:
130104

131105
- **spring.boot.admin.ui.brand**: This HTML snippet is rendered in navigation header and defaults to `<img src="assets/img/icon-spring-boot-admin.svg"><span>Spring Boot Admin</span>`.
132106
By default it shows the SBA logo followed by it's name.
133107
If you want to show a custom logo you can set: `spring.boot.admin.ui.brand=<img src="custom/custom-icon.png">`.
134-
Either you just add the image to your jar-file in `/META-INF/spring-boot-admin-server-ui/` (SBA registers a `ResourceHandler` for this location by default),
135-
or you must ensure yourself that the image gets served correctly (e.g. by registering your own `ResourceHandler`)
108+
Either you just add the image to your jar-file in `/META-INF/spring-boot-admin-server-ui/` (SBA registers a `ResourceHandler` for this location by default), or you must ensure yourself that the image gets served correctly (e.g. by registering your own `ResourceHandler`)
136109

137110
- **spring.boot.admin.ui.title**: Use this option to customize the browsers window title.
138111

139-
=== Customizing Colors ===
112+
== Customizing Colors ==
113+
140114
You can provide a custom color theme to the application by overwriting the following properties:
141115

142116
[source,yaml,indent=0]
143117
----
144118
include::{samples-dir}/spring-boot-admin-sample-servlet/src/main/resources/application-themed.yml[]
145119
----
146120

147-
148121
|===
149122
| Property name | Default | Usage
150123

@@ -180,32 +153,36 @@ stop: #9F2A2A
180153
900: #010603
181154
``
182155
| Define a color palette that affects the colors in sidebar view
183-
(e.g shade `600` of palette is used as text color and shade `50` as background color.)
156+
(e.g shade `600` of palette is used as text color and shade `50` as background color.)
184157

185158
|===
186159

187-
=== Customizing Login Logo ===
160+
== Customizing Login Logo ==
161+
188162
You can set a custom image to be displayed on the login page.
189163

190164
1. Put the image in a resource location which is served via http (e.g. `/META-INF/spring-boot-admin-server-ui/assets/img/`).
191165
2. Configure the icons to use using the following property:
192-
- **spring.boot.admin.ui.login-icon**: Used as icon on login page. (e.g `assets/img/custom-login-icon.svg`)
166+
- **spring.boot.admin.ui.login-icon**: Used as icon on login page. (e.g `assets/img/custom-login-icon.svg`)
193167

194-
=== Customizing Favicon ===
195-
It is possible to use a custom favicon, which is also used for desktop notifications. Spring Boot Admin uses a different icon when one or more application is down.
168+
== Customizing Favicon ==
169+
170+
It is possible to use a custom favicon, which is also used for desktop notifications.
171+
Spring Boot Admin uses a different icon when one or more application is down.
196172

197173
1. Put the favicon (`.png` with at least 192x192 pixels) in a resource location which is served via http (e.g. `/META-INF/spring-boot-admin-server-ui/assets/img/`).
198174

199175
2. Configure the icons to use using the following properties:
200-
- `spring.boot.admin.ui.favicon`: Used as default icon. (e.g `assets/img/custom-favicon.png`
201-
- `spring.boot.admin.ui.favicon-danger`: Used when one or more service is down. (e.g `assets/img/custom-favicon-danger.png`)
176+
- `spring.boot.admin.ui.favicon`: Used as default icon. (e.g `assets/img/custom-favicon.png`
177+
- `spring.boot.admin.ui.favicon-danger`: Used when one or more service is down. (e.g `assets/img/custom-favicon-danger.png`)
178+
179+
== Customizing Available Languages ==
202180

203-
=== Customizing Available Languages ===
204181
To filter languages to a subset of all supported languages:
205182

206183
- **spring.boot.admin.ui.available-languages**: Used as a filter of existing languages. (e.g `en,de` out of existing `de,en,fr,ko,pt-BR,ru,zh`)
207184

208-
=== Showing / Hiding views ===
185+
== Show / Hide views ==
209186

210187
You can very simply hide views in the navbar:
211188

spring-boot-admin-docs/src/site/asciidoc/templates/paragraph.html.slim

Lines changed: 0 additions & 1 deletion
This file was deleted.

spring-boot-admin-docs/src/site/resources/css/custom.css

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ body::before {
1111
display: block;
1212
height: 200px;
1313
left: 0;
14-
position: absolute;
14+
position: fixed;
1515
width: 100%;
1616
z-index: -1;
1717
}
@@ -33,7 +33,7 @@ body::before {
3333
#main-section {
3434
display: flex;
3535
flex-direction: column;
36-
margin-top: 60px;
36+
margin-top: 80px;
3737
}
3838

3939
#footer-info {
@@ -44,6 +44,11 @@ body::before {
4444
font-size: .8em;
4545
}
4646

47+
.hljs {
48+
background-color: rgba(240, 240, 240, .75);
49+
backdrop-filter: blur(10px);
50+
}
51+
4752
#footer-info a {
4853
color: #000;
4954
}
Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,48 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/DECORATION/1.8.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="http://maven.apache.org/DECORATION/1.8.0"
44
xsi:schemaLocation="http://maven.apache.org/DECORATION/1.8.0 http://maven.apache.org/xsd/decoration-1.8.0.xsd"
55
name="Spring Boot Admin">
66

77
<skin>
88
<groupId>com.bernardomg.maven.skins</groupId>
99
<artifactId>docs-maven-skin</artifactId>
10-
<version>2.2.7</version>
10+
<version>2.2.9</version>
1111
</skin>
1212

1313
<custom>
1414
<skinConfig>
1515
<bootswatchStyle>litera</bootswatchStyle>
16-
<customStyle>./css/custom.css</customStyle>
16+
<customStyle>/css/custom.css</customStyle>
1717
<topNav>
1818
<menu>Documentation</menu>
1919
<menu>Server</menu>
2020
<menu>Client</menu>
21+
<menu>Customize</menu>
2122
</topNav>
2223
</skinConfig>
2324
</custom>
2425

2526
<body>
2627
<menu name="Documentation" inherit="bottom">
27-
<item name="Getting Started" href="./getting-started.html" />
28-
<item name="Server" href="./server.html" />
29-
<item name="Client" href="./client.html" />
30-
<item name="Security" href="./security.html" />
31-
<item name="FAQ" href="./faq.html" />
28+
<item name="Getting Started" href="./getting-started.html"/>
29+
<item name="Server" href="./server.html"/>
30+
<item name="Client" href="./client.html"/>
31+
<item name="Security" href="./security.html"/>
32+
<item name="FAQ" href="./faq.html"/>
3233
</menu>
3334
<menu name="Server" inherit="top">
34-
<item name="Usage" href="./server.html" />
35-
<item name="Notifications" href="./server-notifications.html" />
35+
<item name="Usage" href="./server.html"/>
36+
<item name="Notifications" href="./server-notifications.html"/>
3637
</menu>
3738
<menu name="Client" inherit="top">
38-
<item name="Usage" href="./client.html" />
39+
<item name="Usage" href="./client.html"/>
40+
</menu>
41+
<menu name="Customize" inherit="top">
42+
<item name="Notifiers" href="./customize_notifiers.html"/>
43+
<item name="HTTP Headers" href="./customize_http-headers.html"/>
44+
<item name="Interceptors" href="./customize_interceptors.html"/>
45+
<item name="UI" href="./customize_ui.html"/>
3946
</menu>
4047
</body>
4148
</project>

0 commit comments

Comments
 (0)