Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefix websocket path with server path #1058

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion app/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want this behaviour? I'd rather avoid getting to deep in to the mess of determining if this is a directory or a file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not getting much activity from the other maintainers, so I'll make the call then. :)

@ryanlovett, please remove this part and it should be okay to merge.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, thanks for the ping! Can you clarify which part should be removed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anything that tries to guess if this is a folder or a file. Just assume everything after the last / should be removed. So /foo/myvnc => /foo/websockify and /bar/vnc.html => /bar/websockify.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, thanks. Should I treat /foo/myvnc/ the same as /foo/myvnc then? (Pedantically) that would go against "assume everything after the last / should be removed" since in the trailing slash case it would remove nothing. But I think it is more in-line with "avoid ... determining if this is a directory or a file".

* /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);
Expand All @@ -164,7 +196,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);
Expand Down