From 4b59e4523bae9451bc7a67bb9bbb6859f56a61fa Mon Sep 17 00:00:00 2001 From: Ryan Lovett Date: Thu, 19 Apr 2018 12:41:36 -0700 Subject: [PATCH] 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);