Skip to content

Commit 58d9faf

Browse files
committed
make webui work with non-root context path
Signed-off-by: Hubert Nusser <[email protected]>
1 parent 6e06022 commit 58d9faf

27 files changed

+74
-43
lines changed

bundles/org.openhab.ui.basic/gulpfile.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
.pipe(gulp.dest("./src/main/resources/web"));
3434
});
3535

36+
gulp.task("tile", function() {
37+
return gulp.src("web-src/tile.png")
38+
.pipe(gulp.dest("./src/main/resources/web"));
39+
});
40+
3641
gulp.task("eslint", function() {
3742
return gulp.src(sources.js)
3843
.pipe(eslint({
@@ -48,5 +53,5 @@
4853
.pipe(gulp.dest("./src/main/resources/web"));
4954
});
5055

51-
gulp.task("default", gulp.parallel("css", "copyFontLibs", gulp.series("eslint", "js")));
56+
gulp.task("default", gulp.parallel("css", "tile", "copyFontLibs", gulp.series("eslint", "js")));
5257
})();

bundles/org.openhab.ui/web/.eslintrc.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ module.exports = {
3131
'ga': true, // Google Analytics
3232
'cordova': true,
3333
'__statics': true,
34-
'process': true
34+
'process': true,
35+
'baseUrl': true
3536
},
3637

3738
// add your custom rules here

bundles/org.openhab.ui/web/build/webpack.config.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ module.exports = {
204204
new HtmlWebpackPlugin({
205205
filename: './index.html',
206206
template: './src/index.html',
207-
inject: true,
207+
inject: false,
208208
minify: env === 'production' ? {
209209
collapseWhitespace: true,
210210
removeComments: true,
@@ -219,8 +219,8 @@ module.exports = {
219219
}),
220220
new CopyWebpackPlugin([
221221
{
222-
from: resolvePath('src/res'),
223-
to: resolvePath(isCordova ? 'cordova/www/res' : 'www/res')
222+
from: resolvePath('src/images'),
223+
to: resolvePath(isCordova ? 'cordova/www/images' : 'www/images')
224224
},
225225
{
226226
from: resolvePath('src/manifest.json'),

bundles/org.openhab.ui/web/src/components/app.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ export default {
307307
iosSwipeBack: !this.$device.ios || this.$device.cordova,
308308
auroraSwipeBack: !this.$device.ios || this.$device.cordova,
309309
pushState: true, // !this.$device.cordova
310+
pushStateRoot: baseUrl,
310311
pushStateSeparator: ''
311312
},
312313
// Enable panel left visibility breakpoint
@@ -510,7 +511,7 @@ export default {
510511
this.cleanSession().then(() => {
511512
this.loggedIn = false
512513
this.$f7.views.main.router.navigate('/', { animate: false, clearPreviousHistory: true })
513-
window.location = window.location.origin
514+
window.location = window.location.origin + baseUrl + '/'
514515
if (this.$device.cordova) {
515516
this.loginScreenOpened = true
516517
}

bundles/org.openhab.ui/web/src/components/auth-mixin.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ export default {
3131

3232
const payload = Utils.serializeObject({
3333
'grant_type': 'authorization_code',
34-
'client_id': window.location.origin,
35-
'redirect_uri': window.location.origin,
34+
'client_id': window.location.origin + baseUrl,
35+
'redirect_uri': window.location.origin + baseUrl + '/',
3636
'code': queryParams.code,
3737
'code_verifier': codeVerifier
3838
})
@@ -65,8 +65,8 @@ export default {
6565
const refreshToken = this.getRefreshToken()
6666
const payload = Utils.serializeObject({
6767
'grant_type': 'refresh_token',
68-
'client_id': window.location.origin,
69-
'redirect_uri': window.location.origin,
68+
'client_id': window.location.origin + baseUrl,
69+
'redirect_uri': window.location.origin + baseUrl + '/',
7070
'refresh_token': refreshToken
7171
})
7272

bundles/org.openhab.ui/web/src/css/icons.css

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
font-weight: 400;
66
src: local('Material Icons'),
77
local('MaterialIcons-Regular'),
8-
url(../fonts/MaterialIcons-Regular.woff2) format('woff2'),
9-
url(../fonts/MaterialIcons-Regular.woff) format('woff'),
10-
url(../fonts/MaterialIcons-Regular.ttf) format('truetype');
8+
url("../fonts/MaterialIcons-Regular.woff2") format('woff2'),
9+
url("../fonts/MaterialIcons-Regular.woff") format('woff'),
10+
url("../fonts/MaterialIcons-Regular.ttf") format('truetype');
1111
}
1212
.material-icons {
1313
font-family: 'Material Icons';

bundles/org.openhab.ui/web/src/index.html

+16-5
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,29 @@
2121
<% if (process.env.TARGET === 'web') { %>
2222
<meta name="apple-mobile-web-app-capable" content="yes">
2323
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
24-
<link rel="apple-touch-icon" href="/res/icons/apple-touch-icon.png" type="image/png" sizes="180x180" crossorigin="use-credentials">
25-
<link rel="icon" href="/res/icons/favicon.svg" type="image/svg+xml" sizes="any" crossorigin="use-credentials">
26-
<link rel="icon" href="/res/icons/128x128.png" type="image/png" sizes="128x128" crossorigin="use-credentials">
27-
<link rel="manifest" href="/manifest.json" crossorigin="use-credentials">
24+
<link rel="apple-touch-icon" href="images/icons/apple-touch-icon.png" type="image/png" sizes="180x180" crossorigin="use-credentials">
25+
<link rel="icon" href="images/icons/favicon.svg" type="image/svg+xml" sizes="any" crossorigin="use-credentials">
26+
<link rel="icon" href="images/icons/128x128.png" type="image/png" sizes="128x128" crossorigin="use-credentials">
27+
<link rel="manifest" href="manifest.json" crossorigin="use-credentials">
2828
<% } %>
2929
<!-- built styles file will be auto injected -->
30+
<script>
31+
const baseUrl = document.cookie.match('(^|;)\\s*X-OPENHAB-BASEURL\\s*=\\s*([^;]+)')?.pop().replace(/\/$/, '') || '';
32+
33+
var base = document.createElement('base');
34+
base.href = baseUrl + '/';
35+
document.head.appendChild(base);
36+
</script>
3037
</head>
3138
<body>
3239
<div id="app"></div>
3340
<% if (process.env.TARGET === 'cordova') { %>
3441
<script src="cordova.js"></script>
3542
<% } %>
36-
<!-- built script files will be auto injected -->
43+
<script>
44+
let app = document.createElement('script');
45+
app.setAttribute('src', baseUrl + "/js/app.js");
46+
document.body.appendChild(app);
47+
</script>
3748
</body>
3849
</html>

bundles/org.openhab.ui/web/src/js/app.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import './public-path.js'
12
import './compatibility'
23

34
// Import Vue

bundles/org.openhab.ui/web/src/js/openhab/api.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,24 @@ Framework7.request.setup({
2828

2929
export default {
3030
get (uri, data) {
31-
return wrapPromise(Framework7.request.promise.json(uri, data))
31+
return wrapPromise(Framework7.request.promise.json(baseUrl + uri, data))
3232
},
3333
getPlain (uri, data, contentType) {
3434
return wrapPromise(Framework7.request.promise({
3535
method: 'GET',
36-
url: uri,
36+
url: baseUrl + uri,
3737
data,
3838
processData: false,
3939
contentType: contentType || 'text/plain'
4040
}))
4141
},
4242
post (uri, data, dataType) {
43-
return wrapPromise(Framework7.request.promise.postJSON(uri, data, dataType))
43+
return wrapPromise(Framework7.request.promise.postJSON(baseUrl + uri, data, dataType))
4444
},
4545
postPlain (uri, data, dataType, contentType) {
4646
return wrapPromise(Framework7.request.promise({
4747
method: 'POST',
48-
url: uri,
48+
url: baseUrl + uri,
4949
data,
5050
processData: false,
5151
contentType: contentType || 'text/plain',
@@ -55,7 +55,7 @@ export default {
5555
put (uri, data) {
5656
return wrapPromise(Framework7.request.promise({
5757
method: 'PUT',
58-
url: uri,
58+
url: baseUrl + uri,
5959
data: JSON.stringify(data),
6060
processData: false,
6161
// dataType: 'json',
@@ -65,7 +65,7 @@ export default {
6565
putPlain (uri, data, dataType, contentType) {
6666
return wrapPromise(Framework7.request.promise({
6767
method: 'PUT',
68-
url: uri,
68+
url: baseUrl + uri,
6969
data,
7070
processData: false,
7171
// dataType: 'json',
@@ -76,13 +76,13 @@ export default {
7676
head (uri) {
7777
return wrapPromise(Framework7.request.promise({
7878
method: 'HEAD',
79-
url: uri
79+
url: baseUrl + uri
8080
}))
8181
},
8282
delete (uri, data) {
8383
return wrapPromise(Framework7.request.promise({
8484
method: 'DELETE',
85-
url: uri,
85+
url: baseUrl + uri,
8686
processData: false,
8787
// dataType: 'json',
8888
contentType: 'application/json'

bundles/org.openhab.ui/web/src/js/openhab/auth.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ export function authorize (setup) {
3535
sessionStorage.setItem('openhab.ui:codeVerifier', pkceChallenge.code_verifier)
3636
sessionStorage.setItem('openhab.ui:authState', authState)
3737

38-
window.location = '/auth' +
38+
window.location = baseUrl + '/auth' +
3939
'?response_type=code' +
40-
'&client_id=' + encodeURIComponent(window.location.origin) +
41-
'&redirect_uri=' + encodeURIComponent(window.location.origin) +
40+
'&client_id=' + encodeURIComponent(window.location.origin + baseUrl) +
41+
'&redirect_uri=' + encodeURIComponent(window.location.origin + baseUrl + '/') +
4242
'&scope=admin' +
4343
'&code_challenge_method=S256' +
4444
'&code_challenge=' + encodeURIComponent(pkceChallenge.code_challenge) +

bundles/org.openhab.ui/web/src/js/openhab/sse.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ function newSSEConnection (path, readyCallback, messageCallback, errorCallback)
5353

5454
export default {
5555
connect (path, topics, messageCallback, errorCallback) {
56-
return newSSEConnection(path, null, messageCallback, errorCallback)
56+
return newSSEConnection(baseUrl + path, null, messageCallback, errorCallback)
5757
},
5858
connectStateTracker (path, readyCallback, updateCallback, errorCallback) {
59-
return newSSEConnection(path, readyCallback, updateCallback, errorCallback)
59+
return newSSEConnection(baseUrl + path, readyCallback, updateCallback, errorCallback)
6060
},
6161
close (client, callback) {
6262
if (!client) return
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/* global __webpack_public_path__:writable */
2+
__webpack_public_path__ = baseUrl + '/'

bundles/org.openhab.ui/web/src/js/routes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ export default [
299299
},
300300
/* For Cordova */
301301
{
302-
path: '/res/(.*)',
302+
path: '/images/(.*)',
303303
redirect: '/'
304304
},
305305
{

bundles/org.openhab.ui/web/src/manifest.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,32 @@
99
"theme_color": "#e64a19",
1010
"icons": [
1111
{
12-
"src": "/res/icons/128x128.png",
12+
"src": "images/icons/128x128.png",
1313
"sizes": "128x128",
1414
"type": "image/png"
1515
},
1616
{
17-
"src": "/res/icons/144x144.png",
17+
"src": "images/icons/144x144.png",
1818
"sizes": "144x144",
1919
"type": "image/png"
2020
},
2121
{
22-
"src": "/res/icons/152x152.png",
22+
"src": "images/icons/152x152.png",
2323
"sizes": "152x152",
2424
"type": "image/png"
2525
},
2626
{
27-
"src": "/res/icons/192x192.png",
27+
"src": "images/icons/192x192.png",
2828
"sizes": "192x192",
2929
"type": "image/png"
3030
},
3131
{
32-
"src": "/res/icons/256x256.png",
32+
"src": "images/icons/256x256.png",
3333
"sizes": "256x256",
3434
"type": "image/png"
3535
},
3636
{
37-
"src": "/res/icons/512x512.png",
37+
"src": "images/icons/512x512.png",
3838
"sizes": "512x512",
3939
"type": "image/png"
4040
}

bundles/org.openhab.ui/web/src/pages/about.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<f7-col>
77
<!-- <f7-block-title>About openHAB</f7-block-title> -->
88
<f7-block>
9-
<img src="../res/icons/favicon.svg" type="image/svg+xml" width="96" class="padding float-right">
9+
<img src="@/images/icons/favicon.svg" type="image/svg+xml" width="96" class="padding float-right">
1010
<h2 v-if="$store.state.runtimeInfo" class="block-title-medium">
1111
openHAB {{ $store.state.runtimeInfo.version }}<br><small>{{ $store.state.runtimeInfo.buildString }}</small>
1212
</h2>

bundles/org.openhab.ui/web/src/pages/panel-right.vue

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ export default {
2424
},
2525
created () {
2626
this.$oh.api.get('/rest/ui/tiles').then((data) => {
27-
this.apps = data
27+
this.apps = data.map((tile) => {
28+
tile.url = baseUrl + tile.url
29+
tile.imageUrl = baseUrl + tile.imageUrl
30+
return tile
31+
})
2832
})
2933
}
3034
}

bundles/org.openhab.ui/web/src/pages/profile.vue

+9-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<f7-row>
2121
<f7-col>
2222
<f7-list>
23-
<f7-list-button color="blue" :external="true" href="/changePassword">
23+
<f7-list-button color="blue" :external="true" :href="changePasswordUrl()">
2424
{{ $t('profile.changePassword') }}
2525
</f7-list-button>
2626
</f7-list>
@@ -77,7 +77,7 @@
7777
</f7-swipeout-button>
7878
</f7-swipeout-actions>
7979
</f7-list-item>
80-
<f7-list-button color="blue" :external="true" href="/createApiToken">
80+
<f7-list-button color="blue" :external="true" :href="createApiTokenUrl()">
8181
{{ $t('profile.apiTokens.create') }}
8282
</f7-list-button>
8383
</f7-list>
@@ -216,14 +216,20 @@ export default {
216216
this.cleanSession().then(() => {
217217
this.loggedIn = false
218218
this.$f7.views.main.router.navigate('/', { animate: false, clearPreviousHistory: true })
219-
window.location = window.location.origin
219+
window.location = window.location.origin + baseUrl
220220
if (this.$device.cordova) {
221221
this.loginScreenOpened = true
222222
}
223223
}).catch((err) => {
224224
this.$f7.preloader.hide()
225225
this.$f7.dialog.alert(this.$t('profile.sessions.signOut.error') + err)
226226
})
227+
},
228+
changePasswordUrl () {
229+
return baseUrl + '/changePassword'
230+
},
231+
createApiTokenUrl () {
232+
return baseUrl + '/createApiToken'
227233
}
228234
}
229235
}
Binary file not shown.

0 commit comments

Comments
 (0)