From 4b59e4523bae9451bc7a67bb9bbb6859f56a61fa Mon Sep 17 00:00:00 2001 From: Ryan Lovett Date: Thu, 19 Apr 2018 12:41:36 -0700 Subject: [PATCH 1/3] 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. --- app/ui.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/ui.js b/app/ui.js index f3c6d46d..78decb5d 100644 --- a/app/ui.js +++ b/app/ui.js @@ -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); From e2e07e147b6241851ed32b9065ef4096ad54cedf Mon Sep 17 00:00:00 2001 From: ryanlovett Date: Mon, 30 Apr 2018 15:51:29 -0700 Subject: [PATCH 2/3] Don't use landing page in websocket path. --- app/ui.js | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/app/ui.js b/app/ui.js index 78decb5d..ed950ff5 100644 --- a/app/ui.js +++ b/app/ui.js @@ -156,17 +156,38 @@ var 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 + * /foo/myvnc/vnc_lite.html + */ var path = 'websockify'; + var landing_pages = ['vnc.html', 'vnc_lite.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 + 'websockify'; + path = pathName + path; } else { - // There's no trailing slash. - path = pathName + '/websockify'; + // 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 one of our landing pages, rewind to its parent + // directory. Otherwise we assume we are already in a directory. + for (var i=0; i Date: Mon, 30 Apr 2018 16:17:56 -0700 Subject: [PATCH 3/3] Do not treat vnc_lite.html as a landing page. vnc_lite.html does not use ui.js. --- app/ui.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/ui.js b/app/ui.js index ed950ff5..887392dd 100644 --- a/app/ui.js +++ b/app/ui.js @@ -163,10 +163,9 @@ var UI = { * /foo/myvnc /foo/myvnc/websockify * /foo/myvnc/ * /foo/myvnc/vnc.html - * /foo/myvnc/vnc_lite.html */ var path = 'websockify'; - var landing_pages = ['vnc.html', 'vnc_lite.html']; + 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); @@ -179,12 +178,10 @@ var UI = { var pathElements = pathName.split('/'); var pathLast = pathElements.pop(); - // If we are at one of our landing pages, rewind to its parent + // If we are at our landing page, rewind to its parent // directory. Otherwise we assume we are already in a directory. - for (var i=0; i