This commit is contained in:
Ryan Lovett 2018-09-03 22:18:22 +00:00 committed by GitHub
commit e7882e1929
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 33 additions and 1 deletions

View File

@ -153,6 +153,38 @@ const UI = {
}
}
/*
* If novnc is hosted at PATHNAME, the default ws path should be at WS:
* PATHNAME WS
* / /websockify
* /foo/myvnc /foo/myvnc/websockify
* /foo/myvnc/
* /foo/myvnc/vnc.html
*/
var path = 'websockify';
var landing_page = 'vnc.html';
// 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 + path;
} else {
// If there is no trailing slash, we may not be at a directory.
var pathElements = pathName.split('/');
var pathLast = pathElements.pop();
// If we are at our landing page, rewind to its parent
// directory. Otherwise we assume we are already in a directory.
if (pathLast == landing_page) {
pathName = pathElements.join('/');
}
path = pathName + '/' + path;
}
}
/* Populate the controls if defaults are provided in the URL */
UI.initSetting('host', window.location.hostname);
UI.initSetting('port', port);
@ -161,7 +193,7 @@ const 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);