http: Add static files hosting

This commit is contained in:
Stein Magnus Jodal 2012-11-09 13:27:27 +01:00
parent 256c5a8179
commit a2259fad57
3 changed files with 32 additions and 7 deletions

View File

@ -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**

View File

@ -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):

View File

@ -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 <http://www.last.fm/>`_ username.
#:
#: Used by :mod:`mopidy.frontends.lastfm`.