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);