Skip to content

Use relative path for websocket #3

@andrenarchy

Description

@andrenarchy

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() in order to determine the path:

var url = require("url");
var path = url.resolve(
    (typeof document !== "undefined" && document.location.pathname) || "/",
    "../mopidy/ws"
);

and then

settings.webSocketUrl = settings.webSocketUrl ||
    protocol + currentHost + path;

In 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.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions