diff --git a/mopidy/frontends/http/__init__.py b/mopidy/frontends/http/__init__.py index ab5c3e22..d674e1d0 100644 --- a/mopidy/frontends/http/__init__.py +++ b/mopidy/frontends/http/__init__.py @@ -13,18 +13,22 @@ Frontend which lets you control Mopidy through HTTP and WebSockets. - :attr:`mopidy.settings.HTTP_SERVER_PORT` +- :attr:`mopidy.settings.HTTP_SERVER_STATIC_DIR` + **Usage** When this frontend is included in :attr:`mopidy.settings.FRONTENDS`, it starts a web server at the port specified by :attr:`mopidy.settings.HTTP_SERVER_PORT`. + This web server exposes both a REST web service at the URL ``/api``, and a -WebSocket at ``/ws``. +WebSocket at ``/ws``. The REST API gives you access to most Mopidy +functionality, while the WebSocket enables Mopidy to instantly push events to +the client, as they happen. -The REST API gives you access to most Mopidy functionality, while the WebSocket -enables Mopidy to instantly push events to the client, as they happen. - -It is also the intention that the frontend should be able to host static files -for any external JavaScript client. This has currently not been implemented. +The web server can also host any static files, for example the HTML, CSS, +JavaScript and images needed by a web based Mopidy client. To host static +files, change :attr:`mopidy.settings.HTTP_SERVER_STATIC_DIR` to point to the +directory you want to serve. **API stability** diff --git a/mopidy/frontends/http/actor.py b/mopidy/frontends/http/actor.py index c9ae651e..5c997f79 100644 --- a/mopidy/frontends/http/actor.py +++ b/mopidy/frontends/http/actor.py @@ -43,12 +43,23 @@ class HttpFrontend(pykka.ThreadingActor, CoreListener): root = RootResource() root.api = api.ApiResource(self.core) root.ws = ws.WebSocketResource() + config = { '/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/settings.py b/mopidy/settings.py index 36057869..3603eda6 100644 --- a/mopidy/settings.py +++ b/mopidy/settings.py @@ -49,7 +49,7 @@ DEBUG_LOG_FILENAME = u'mopidy.log' #: get a SIGUSR1. Mainly a debug tool for figuring out deadlocks. #: #: Default:: -#: +#: #: DEBUG_THREAD = False DEBUG_THREAD = False @@ -101,6 +101,16 @@ HTTP_SERVER_HOSTNAME = u'127.0.0.1' #: Default: 6680 HTTP_SERVER_PORT = 6680 +#: Which directory Mopidy's HTTP server should serve at /. +#: +#: Change this to have Mopidy serve e.g. files for your JavaScript client. +#: /api and /ws will continue to work as usual even if you change this setting. +#: +#: Used by :mod:`mopidy.frontends.http`. +#: +#: Default: None +HTTP_SERVER_STATIC_DIR = None + #: Your `Last.fm `_ username. #: #: Used by :mod:`mopidy.frontends.lastfm`.