Skip to content

Commit 0ec9ca9

Browse files
committed
Externalize the inline script from index.html
closes #1155
1 parent a5b9bca commit 0ec9ca9

File tree

4 files changed

+40
-17
lines changed

4 files changed

+40
-17
lines changed

spring-boot-admin-server-ui/src/main/frontend/index.html

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,7 @@
4242

4343
<div id="app"></div>
4444

45-
<script th:inline="javascript">
46-
var SBA = {
47-
uiSettings: /*[[${uiSettings}]]*/ {},
48-
user: /*[[${user}]]*/ null,
49-
extensions: [],
50-
/*[#th:block th:if="${_csrf}"]*/
51-
csrf: {
52-
parameterName: /*[[${_csrf.parameterName}]]*/ null,
53-
headerName: /*[[${_csrf.headerName}]]*/ null
54-
},
55-
/*[/th:block]*/
56-
use: function (ext) {
57-
this.extensions.push(ext);
58-
}
59-
}
60-
</script>
45+
<script lang="javascript" src="sba-settings.js"></script>
6146
<!-- include extensions -->
6247
<th:block th:each="jsFile : ${jsExtensions}">
6348
<script lang="javascript" th:src="${jsFile.resourcePath}"></script>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2014-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
//This is a Thymleaf template whill will be rendered by the backend
18+
var SBA = {
19+
uiSettings: /*[[${uiSettings}]]*/ {},
20+
user: /*[[${user}]]*/ null,
21+
extensions: [],
22+
csrf: {
23+
parameterName: /*[[${_csrf} ? ${_csrf.parameterName} : 'null']]*/ null,
24+
headerName: /*[[${_csrf} ? ${_csrf.headerName} : 'null']]*/ null
25+
},
26+
use: function (ext) {
27+
this.extensions.push(ext);
28+
}
29+
};

spring-boot-admin-server-ui/src/main/java/de/codecentric/boot/admin/server/ui/web/UiController.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ public String index() {
106106
return "index";
107107
}
108108

109+
@GetMapping(path = "/sba-settings.js", produces = MediaType.APPLICATION_JSON_VALUE)
110+
public String sbaSettings() {
111+
return "sba-settings.js";
112+
}
113+
109114
@GetMapping(path = "/login", produces = MediaType.TEXT_HTML_VALUE)
110115
public String login() {
111116
return "login";

spring-boot-admin-server-ui/vue.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2018 the original author or authors.
2+
* Copyright 2014-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -80,6 +80,10 @@ module.exports = {
8080
toType: 'dir',
8181
ignore: ['*.scss']
8282
}]),
83+
new CopyPlugin([{
84+
from: resolve(__dirname, 'src/main/frontend/sba-settings.js'),
85+
to: resolve(__dirname, 'target/dist/sba-settings.js'),
86+
}]),
8387
new BundleAnalyzerPlugin({
8488
analyzerMode: 'static',
8589
openAnalyzer: false,

0 commit comments

Comments
 (0)