diff --git a/MANIFEST.in b/MANIFEST.in index f3723ecd..476cd5c1 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -4,6 +4,7 @@ include LICENSE include MANIFEST.in include data/mopidy.desktop include mopidy/backends/spotify/spotify_appkey.key +include mopidy/frontends/http/index.html include pylintrc recursive-include docs * prune docs/_build diff --git a/mopidy/frontends/http/actor.py b/mopidy/frontends/http/actor.py index 5c997f79..7eed0937 100644 --- a/mopidy/frontends/http/actor.py +++ b/mopidy/frontends/http/actor.py @@ -1,4 +1,5 @@ import logging +import os import pykka @@ -44,22 +45,24 @@ class HttpFrontend(pykka.ThreadingActor, CoreListener): root.api = api.ApiResource(self.core) root.ws = ws.WebSocketResource() + if settings.HTTP_SERVER_STATIC_DIR: + static_dir = settings.HTTP_SERVER_STATIC_DIR + else: + static_dir = os.path.dirname(__file__) + logger.debug(u'HTTP server will serve "%s" at /', static_dir) + config = { + '/': { + 'tools.staticdir.on': True, + 'tools.staticdir.index': 'index.html', + 'tools.staticdir.dir': static_dir, + }, '/ws': { 'tools.websocket.on': True, 'tools.websocket.handler_cls': ws.WebSocketHandler, }, } - if settings.HTTP_SERVER_STATIC_DIR: - logger.debug(u'HTTP server will serve "%s" at /', - settings.HTTP_SERVER_STATIC_DIR) - config['/'] = { - 'tools.staticdir.on': True, - 'tools.staticdir.index': 'index.html', - 'tools.staticdir.dir': settings.HTTP_SERVER_STATIC_DIR, - } - return cherrypy.tree.mount(root, '/', config) def _setup_logging(self, app): diff --git a/mopidy/frontends/http/index.html b/mopidy/frontends/http/index.html new file mode 100644 index 00000000..f3f0b208 --- /dev/null +++ b/mopidy/frontends/http/index.html @@ -0,0 +1,111 @@ + + + + + Mopidy HTTP frontend + + + +
+

Mopidy HTTP frontend

+ +

This web server is a part of the music server Mopidy. To learn more + about Mopidy, please visit www.mopidy.com.

+
+ +
+

Static content serving

+ +

To see your own content here, change the setting + HTTP_SERVER_STATIC_DIR to point to the directory containing your + content. This can be used to host a web based Mopidy client here.

+ +

Even if you host your own content on the root of the web server, + you'll always have the following services available.

+
+ +
+

Web service

+ +

Mopidy makes it's API available for use over HTTP at + /api/. The service tries to be RESTful. It serves and + eats JSON data.

+
+ +
+

WebSocket endpoint

+ +

Mopidy has a WebSocket endpoint at /ws/. You can + use WebSockets to get notified about events happening in Mopidy. The + alternative would be to regularly poll the conventional web service for + updates.

+ +

To connect to the endpoint from a browser with WebSocket support, + simply enter the following JavaScript code in the browser's console:

+ +
var ws = new WebSocket("ws://myhost:myport/ws/');
+ws.onmessage = function (event) {
+  console.log("Incoming message: ", event.data);
+};
+ws.send("Message to the server, ahoy!");
+
+ +
+

Documentation

+ +

For more information, please refer to the Mopidy documentation at + docs.mopidy.com.

+
+ +