Prefix websocket path with server path

If noVNC is not served at the root path, prefix the websocket path with the server path. This makes the path to the websocket consistent with the path to all the other web assets. This is convenient so that users do not need to manually change the path setting, though they still can override it.

For example if the websockify server is at /some/sub/dir, with this patch noVNC will connect to /some/sub/dir/websockify rather than /websockify.
This commit is contained in:
Ryan Lovett 2018-04-19 12:41:36 -07:00 committed by GitHub
parent 24231f1ae3
commit 4b59e4523b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 1 deletions

View File

@ -156,6 +156,20 @@ var UI = {
}
}
var path = 'websockify';
// If noVNC is not being served at the root path, prefix
// the default websocket path with the server path.
var pathName = window.location.pathname.slice(1);
if (pathName.length != 0) { // We are not at the root path
if (pathName.slice(-1) == '/') {
// There's a trailing slash.
path = pathName + 'websockify';
} else {
// There's no trailing slash.
path = pathName + '/websockify';
}
}
/* Populate the controls if defaults are provided in the URL */
UI.initSetting('host', window.location.hostname);
UI.initSetting('port', port);
@ -164,7 +178,7 @@ var UI = {
UI.initSetting('resize', 'off');
UI.initSetting('shared', true);
UI.initSetting('view_only', false);
UI.initSetting('path', 'websockify');
UI.initSetting('path', path);
UI.initSetting('repeaterID', '');
UI.initSetting('reconnect', false);
UI.initSetting('reconnect_delay', 5000);