{"action":"created","issue":{"url":"https://api.github.com/repos/mopidy/mopidy.js/issues/3","labels_url":"https://api.github.com/repos/mopidy/mopidy.js/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/mopidy/mopidy.js/issues/3/comments","events_url":"https://api.github.com/repos/mopidy/mopidy.js/issues/3/events","html_url":"https://github.com/mopidy/mopidy.js/issues/3","id":55685141,"number":3,"title":"Use relative path for websocket","user":{"login":"andrenarchy","id":1874116,"avatar_url":"https://avatars.githubusercontent.com/u/1874116?v=3","gravatar_id":"","url":"https://api.github.com/users/andrenarchy","html_url":"https://github.com/andrenarchy","followers_url":"https://api.github.com/users/andrenarchy/followers","following_url":"https://api.github.com/users/andrenarchy/following{/other_user}","gists_url":"https://api.github.com/users/andrenarchy/gists{/gist_id}","starred_url":"https://api.github.com/users/andrenarchy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrenarchy/subscriptions","organizations_url":"https://api.github.com/users/andrenarchy/orgs","repos_url":"https://api.github.com/users/andrenarchy/repos","events_url":"https://api.github.com/users/andrenarchy/events{/privacy}","received_events_url":"https://api.github.com/users/andrenarchy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-01-27T22:35:57Z","updated_at":"2015-01-27T23:29:42Z","closed_at":null,"body":"If the mopidy server is mounted in a subdirectory via a reverse proxy (e.g., `https://domain/mydir`, such that apps are available under `https://domain/mydir/app`), then the default websocket url in https://github.com/mopidy/mopidy.js/blob/master/src/mopidy.js#L65 points to the wrong location. Since the code already uses browserify (yey!), a solution is to use [url.resolve()](http://nodejs.org/api/url.html#url_url_resolve_from_to) in order to determine the path:\r\n```javascript\r\nvar url = require(\"url\");\r\nvar path = url.resolve(\r\n    (typeof document !== \"undefined\" && document.location.pathname) || \"/\",\r\n    \"../mopidy/ws\"\r\n);\r\n```\r\nand then\r\n```javascript\r\nsettings.webSocketUrl = settings.webSocketUrl ||\r\n    protocol + currentHost + path;\r\n```\r\nIn my setup, mopidy is mounted in a subdirectory via nginx and it took me a while to figure out why moped wasn't able to connect to the websocket. The above change would make it work without any further configuration.\r\n\r\nWhat do you think?"},"comment":{"url":"https://api.github.com/repos/mopidy/mopidy.js/issues/comments/71751210","html_url":"https://github.com/mopidy/mopidy.js/issues/3#issuecomment-71751210","issue_url":"https://api.github.com/repos/mopidy/mopidy.js/issues/3","id":71751210,"user":{"login":"andrenarchy","id":1874116,"avatar_url":"https://avatars.githubusercontent.com/u/1874116?v=3","gravatar_id":"","url":"https://api.github.com/users/andrenarchy","html_url":"https://github.com/andrenarchy","followers_url":"https://api.github.com/users/andrenarchy/followers","following_url":"https://api.github.com/users/andrenarchy/following{/other_user}","gists_url":"https://api.github.com/users/andrenarchy/gists{/gist_id}","starred_url":"https://api.github.com/users/andrenarchy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrenarchy/subscriptions","organizations_url":"https://api.github.com/users/andrenarchy/orgs","repos_url":"https://api.github.com/users/andrenarchy/repos","events_url":"https://api.github.com/users/andrenarchy/events{/privacy}","received_events_url":"https://api.github.com/users/andrenarchy/received_events","type":"User","site_admin":false},"created_at":"2015-01-27T23:29:42Z","updated_at":"2015-01-27T23:29:42Z","body":"Some thoughts:\r\n\r\n * if the default websocket URL remains unchanged, then the *user* of the software (i.e., the person who's installing it) will have to modify the source code of the web client if it is made available under a subdirectory and the web client does not expose the websocket URL as an configurable option to the user.\r\n * if the default websocket URL is relative to the web client, then the *developer* of the web client has to take care that the proper websocket URL is used if the client uses subdirectories internally.\r\n\r\nPersonally, I was surprised how difficult it is to let mopidy run in a subdirectory. For example, the *musicbox_webclient* has hard-coded absolute URLs all over the place and isn't usable at all since you can't configure it. *Moped* did a much better job – only the websocket URL was preventing it from running out of the box."}}