Skip to content

Commit 0537e44

Browse files
authored
Follow up PR for ISSUE-136 (#138)
* [ISSUE-136] Update Javascript to make requests to appropriate URL * [ISSUE-136] Update additional javascript generated URLs * [ISSUE-136] Update breadcrumb urls * No longer rewrite font path * Cleanup
1 parent 146b473 commit 0537e44

File tree

11 files changed

+47
-27
lines changed

11 files changed

+47
-27
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
33
and this project adheres to [Semantic Versioning](http://semver.org/).
44

55
## 2.1.4 (UNRELEASED)
6-
- [ISSUE-136](https://github.com/SourceLabOrg/kafka-webview/issues/136) Incomplete fix for running Kafka-Webview behind a reverse proxy. Additional work needs to be done to completely resolve this issue.
6+
- [ISSUE-136](https://github.com/SourceLabOrg/kafka-webview/issues/136) Fix URLs when running Kafka-Webview behind a reverse proxy with a URL prefix. You can configure Kafka WebView by setting the following configuration option in your config.yml file:
7+
8+
```yml
9+
server:
10+
servlet:
11+
context-path: /prefix/here
12+
```
713
814
## 2.1.3 (01/19/2019)
915

kafka-webview-ui/src/main/frontend/gulp-tasks/build-dist.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ gulp.task('replace:vendorsCSS', function(){
136136
'./dist/vendors/css/*.css',
137137
], {base: './'})
138138
.pipe(replace(/img\//g, '\/vendors/img/'))
139-
.pipe(replace(/..\/fonts\//g, '\/vendors/fonts/'))
140139
.pipe(gulp.dest('./'));
141140
});
142141

kafka-webview-ui/src/main/frontend/js/app.js

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@ var ApiClient = {
152152
getCsrfToken: function() {
153153
return jQuery("meta[name='_csrf']").attr("content");
154154
},
155+
baseUrl: null,
156+
getBaseUrl: function() {
157+
if (ApiClient.baseUrl == null) {
158+
ApiClient.baseUrl = jQuery("meta[name='_url_base']").attr("content");
159+
}
160+
return ApiClient.baseUrl;
161+
},
162+
buildUrl: function(url) {
163+
return ApiClient.getBaseUrl() + url;
164+
},
155165
// Returns the CSRF Header name
156166
getCsrfHeader: function() {
157167
var headerName = jQuery("meta[name='_csrf_header']").attr("content");
@@ -164,7 +174,7 @@ var ApiClient = {
164174
consume: function(viewId, params, successCallback) {
165175
jQuery.ajax({
166176
type: 'POST',
167-
url: '/api/consumer/view/' + viewId,
177+
url: ApiClient.buildUrl('api/consumer/view/' + viewId),
168178
dataType: 'json',
169179
contentType: 'application/json',
170180
data: JSON.stringify(params),
@@ -191,7 +201,7 @@ var ApiClient = {
191201
seekTimestamp: function(viewId, unixTimestamp, callback) {
192202
jQuery.ajax({
193203
type: 'POST',
194-
url: '/api/consumer/view/' + viewId + '/timestamp/' + unixTimestamp,
204+
url: ApiClient.buildUrl('api/consumer/view/' + viewId + '/timestamp/' + unixTimestamp),
195205
dataType: 'json',
196206
headers: ApiClient.getCsrfHeader(),
197207
success: callback,
@@ -201,7 +211,7 @@ var ApiClient = {
201211
setConsumerState: function(viewId, partitionOffsetJson, callback) {
202212
jQuery.ajax({
203213
type: 'POST',
204-
url: '/api/consumer/view/' + viewId + '/offsets',
214+
url: ApiClient.buildUrl('api/consumer/view/' + viewId + '/offsets'),
205215
data: partitionOffsetJson,
206216
dataType: 'json',
207217
headers: ApiClient.getCsrfHeader(),
@@ -219,64 +229,64 @@ var ApiClient = {
219229
*/
220230
getPartitionsForView: function(viewId, callback) {
221231
jQuery
222-
.getJSON('/api/view/' + viewId + '/partitions', '', callback)
232+
.getJSON(ApiClient.buildUrl('api/view/' + viewId + '/partitions'), '', callback)
223233
.fail(ApiClient.defaultErrorHandler);
224234
},
225235

226236
// Retrieve cluster node info
227237
getClusterNodes: function(clusterId, callback) {
228238
jQuery
229-
.getJSON('/api/cluster/' + clusterId + '/nodes', '', callback)
239+
.getJSON(ApiClient.buildUrl('api/cluster/' + clusterId + '/nodes'), '', callback)
230240
.fail(ApiClient.defaultErrorHandler);
231241
},
232242
getTopicDetails: function(clusterId, topic, callback) {
233243
jQuery
234-
.getJSON('/api/cluster/' + clusterId + '/topic/' + topic + '/details', '', callback)
244+
.getJSON(ApiClient.buildUrl('api/cluster/' + clusterId + '/topic/' + topic + '/details'), '', callback)
235245
.fail(ApiClient.defaultErrorHandler);
236246
},
237247
getAllTopicsDetails: function(clusterId, callback) {
238248
jQuery
239-
.getJSON('/api/cluster/' + clusterId + '/topics/details', '', callback)
249+
.getJSON(ApiClient.buildUrl('api/cluster/' + clusterId + '/topics/details'), '', callback)
240250
.fail(ApiClient.defaultErrorHandler);
241251
},
242252
getTopics: function(clusterId, callback) {
243253
jQuery
244-
.getJSON('/api/cluster/' + clusterId + '/topics/list', '', callback)
254+
.getJSON(ApiClient.buildUrl('api/cluster/' + clusterId + '/topics/list'), '', callback)
245255
.fail(ApiClient.defaultErrorHandler);
246256
},
247257
getTopicConfig: function(clusterId, topic, callback) {
248258
jQuery
249-
.getJSON('/api/cluster/' + clusterId + '/topic/' + topic + '/config', '', callback)
259+
.getJSON(ApiClient.buildUrl('api/cluster/' + clusterId + '/topic/' + topic + '/config'), '', callback)
250260
.fail(ApiClient.defaultErrorHandler);
251261
},
252262
getBrokerConfig: function(clusterId, brokerId, callback) {
253263
jQuery
254-
.getJSON('/api/cluster/' + clusterId + '/broker/' + brokerId + '/config', '', callback)
264+
.getJSON(ApiClient.buildUrl('api/cluster/' + clusterId + '/broker/' + brokerId + '/config'), '', callback)
255265
.fail(ApiClient.defaultErrorHandler);
256266
},
257267
getAllConsumers: function(clusterId, callback) {
258268
jQuery
259-
.getJSON('/api/cluster/' + clusterId + '/consumers', '', callback)
269+
.getJSON(ApiClient.buildUrl('api/cluster/' + clusterId + '/consumers'), '', callback)
260270
.fail(ApiClient.defaultErrorHandler);
261271
},
262272
getAllConsumersWithDetails: function(clusterId, callback) {
263273
jQuery
264-
.getJSON('/api/cluster/' + clusterId + '/consumersAndDetails', '', callback)
274+
.getJSON(ApiClient.buildUrl('api/cluster/' + clusterId + '/consumersAndDetails'), '', callback)
265275
.fail(ApiClient.defaultErrorHandler);
266276
},
267277
getConsumerDetails: function(clusterId, consumerGroupId, callback) {
268278
jQuery
269-
.getJSON('/api/cluster/' + clusterId + '/consumer/' + consumerGroupId + '/details', '', callback)
279+
.getJSON(ApiClient.buildUrl('api/cluster/' + clusterId + '/consumer/' + consumerGroupId + '/details'), '', callback)
270280
.fail(ApiClient.defaultErrorHandler);
271281
},
272282
getConsumerOffsets: function(clusterId, consumerGroupId, callback) {
273283
jQuery
274-
.getJSON('/api/cluster/' + clusterId + '/consumer/' + consumerGroupId + '/offsets', '', callback)
284+
.getJSON(ApiClient.buildUrl('api/cluster/' + clusterId + '/consumer/' + consumerGroupId + '/offsets'), '', callback)
275285
.fail(ApiClient.defaultErrorHandler);
276286
},
277287
getConsumerOffsetsWithTailPositions: function(clusterId, consumerGroupId, callback) {
278288
jQuery
279-
.getJSON('/api/cluster/' + clusterId + '/consumer/' + consumerGroupId + '/offsetsAndTailPositions', '', callback)
289+
.getJSON(ApiClient.buildUrl('api/cluster/' + clusterId + '/consumer/' + consumerGroupId + '/offsetsAndTailPositions'), '', callback)
280290
.fail(ApiClient.defaultErrorHandler);
281291
},
282292
removeConsumer: function(clusterId, consumerId, callback) {
@@ -286,7 +296,7 @@ var ApiClient = {
286296
});
287297
jQuery.ajax({
288298
type: 'POST',
289-
url: '/api/cluster/' + clusterId + '/consumer/remove',
299+
url: ApiClient.buildUrl('api/cluster/' + clusterId + '/consumer/remove'),
290300
data: payload,
291301
dataType: 'json',
292302
headers: ApiClient.getCsrfHeader(),
@@ -305,7 +315,7 @@ var ApiClient = {
305315
});
306316
jQuery.ajax({
307317
type: 'POST',
308-
url: '/api/cluster/' + clusterId + '/create/topic',
318+
url: ApiClient.buildUrl('api/cluster/' + clusterId + '/create/topic'),
309319
data: payload,
310320
dataType: 'json',
311321
headers: ApiClient.getCsrfHeader(),
@@ -326,7 +336,7 @@ var ApiClient = {
326336
var payload = JSON.stringify(payloadJson);
327337
jQuery.ajax({
328338
type: 'POST',
329-
url: '/api/cluster/' + clusterId + '/modify/topic',
339+
url: ApiClient.buildUrl('api/cluster/' + clusterId + '/modify/topic'),
330340
data: payload,
331341
dataType: 'json',
332342
headers: ApiClient.getCsrfHeader(),

kafka-webview-ui/src/main/resources/templates/404.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<meta name="keyword" content="Kafka WebView">
2020
<meta name="_csrf" th:content="${_csrf.token}"/>
2121
<meta name="_csrf_header" th:content="${_csrf.headerName}"/>
22+
<meta name="_url_base" th:content="@{/}"/>
2223
<link rel="shortcut icon" th:href="@{/img/favicon.png}">
2324
<title>Error!</title>
2425

kafka-webview-ui/src/main/resources/templates/cluster/read.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ <h4 class="alert-heading">No Consumers Found</h4>
358358
<script id="nodes-template" type="text/x-handlebars-template">
359359
<tr>
360360
<td>
361-
<a href="/cluster/{{clusterId}}/broker/{{id}}">{{id}}</a>
361+
<a th:href="@{/cluster/{{clusterId}}/broker/{{id}}}">{{id}}</a>
362362
</td>
363363
<td>{{host}}:{{port}}</td>
364364
<td>
@@ -375,7 +375,7 @@ <h4 class="alert-heading">No Consumers Found</h4>
375375
<script id="topics-template" type="text/x-handlebars-template">
376376
<tr>
377377
<td>
378-
<a href="/cluster/{{clusterId}}/topic/{{encodedTopic}}">
378+
<a th:href="@{/cluster/{{clusterId}}/topic/{{encodedTopic}}}">
379379
{{topic}}
380380
</a>
381381
</td>
@@ -397,7 +397,7 @@ <h4 class="alert-heading">No Consumers Found</h4>
397397
<script id="consumers-template" type="text/x-handlebars-template">
398398
<tr>
399399
<td>
400-
<a href="/cluster/{{clusterId}}/consumer/{{encodedId}}">
400+
<a th:href="@{/cluster/{{clusterId}}/consumer/{{encodedId}}}">
401401
{{id}}
402402
</a>
403403
</td>

kafka-webview-ui/src/main/resources/templates/cluster/readBroker.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ <h4 class="alert-heading">Broker Not Found</h4>
238238
<script id="broker-template" type="text/x-handlebars-template">
239239
<tr>
240240
<td>
241-
<a href="/cluster/{{clusterId}}/topic/{{encodedTopic}}">
241+
<a th:href="@{/cluster/{{clusterId}}/topic/{{encodedTopic}}}">
242242
{{topic}}
243243
</a>
244244
</td>

kafka-webview-ui/src/main/resources/templates/cluster/readTopic.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ <h4 class="alert-heading">Topic Not Found</h4>
243243
<tr>
244244
<td>{{partition}}</td>
245245
<td>
246-
<a href="/cluster/{{clusterId}}/broker/{{leaderId}}">
246+
<a th:href="@{/cluster/{{clusterId}}/broker/{{leaderId}}}">
247247
{{leaderHost}}
248248
</a> ( {{leaderId}} )
249249
</td>

kafka-webview-ui/src/main/resources/templates/configuration/cluster/create.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ <h6>SASL Settings</h6>
287287
<i class="fa fa-dot-circle-o"></i>
288288
Submit
289289
</button>
290-
<a class="btn btn-sm btn-danger" href="/configuration/cluster" role="button">
290+
<a class="btn btn-sm btn-danger" th:href="@{/configuration/cluster}" role="button">
291291
<i class="fa fa-ban"></i>
292292
Cancel
293293
</a>

kafka-webview-ui/src/main/resources/templates/error.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<meta name="keyword" content="Kafka WebView">
2020
<meta name="_csrf" th:content="${_csrf.token}"/>
2121
<meta name="_csrf_header" th:content="${_csrf.headerName}"/>
22+
<meta name="_url_base" th:content="@{/}"/>
2223
<link rel="shortcut icon" th:href="@{/img/favicon.png}">
2324
<title>Error!</title>
2425

kafka-webview-ui/src/main/resources/templates/layout.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
<meta name="keyword" content="Kafka WebView">
2222
<meta name="_csrf" th:content="${_csrf.token}"/>
2323
<meta name="_csrf_header" th:content="${_csrf.headerName}"/>
24+
<meta name="_url_base" th:content="@{/}"/>
25+
2426
<link rel="shortcut icon" th:href="@{/img/favicon.png}">
2527
<title>Kafka WebView</title>
2628

@@ -211,7 +213,7 @@
211213
<!-- Handles showing breadcrumbs -->
212214
<ol class="breadcrumb" th:if="${BreadCrumbs != null}">
213215
<li class="breadcrumb-item" th:classappend="${itrStat.last} ? 'active'" th:each="crumb, itrStat: ${BreadCrumbs.getCrumbs()}">
214-
<a th:if="${crumb.url != null}" th:href="${crumb.url}" th:text="${crumb.name}"></a>
216+
<a th:if="${crumb.url != null}" th:href="@{${crumb.url}}" th:text="${crumb.name}"></a>
215217
<span th:if="${crumb.url == null}" th:text="${crumb.name}"></span>
216218
</li>
217219

0 commit comments

Comments
 (0)