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 noVNC 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-18 17:07:44 -07:00 committed by GitHub
parent 24231f1ae3
commit 2ba5cdb454
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 0 deletions

View File

@ -187,6 +187,20 @@
}
var password = WebUtil.getConfigVar('password', '');
var defaultPath = '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.
defaultPath = pathName + 'websockify';
} else {
// There's no trailing slash.
defaultPath = pathName + '/websockify';
}
}
var path = WebUtil.getConfigVar('path', 'websockify');
// If a token variable is passed in, set the parameter in a cookie.