commit dbb7005aa866cdc337bde9c8169e9bf15e5c8042
Author: dz0ny <dz0ny@ubuntu.si>
Date: Sun May 11 22:12:58 2014 +0200
Fix: Make PR mergable
commit 5bb27da72c4276a930bf33955e6583f6781d23f6
Author: dz0ny <dz0ny@ubuntu.si>
Date: Thu May 8 23:31:54 2014 +0200
Add: helper method for extensin url
commit 8a348b26b65102084a606ff73384a478bb785cf1
Author: dz0ny <dz0ny@ubuntu.si>
Date: Thu May 8 00:35:50 2014 +0200
Add: Refactor ws and rpc to handlers, reuse code
commit 677c809d2b39a6c982ab835368fdb8a3ad9d1a92
Author: dz0ny <dz0ny@ubuntu.si>
Date: Thu May 8 00:18:10 2014 +0200
Fix: Return proper HTTP headers
commit fe5fea2fc2a0d28a39532d6d4cd2b21013d57d24
Author: dz0ny <dz0ny@ubuntu.si>
Date: Wed May 7 23:48:19 2014 +0200
Add: RPC post handler
Add: tests for http post handler
commit e77e60310853b368758b09b303a96a95ff1b9b93
Author: dz0ny <dz0ny@ubuntu.si>
Date: Sun May 4 22:15:04 2014 +0200
Add: Documentation on how to extend http api
commit a3a14fb5d15f095e5bab23a590e0a8360a039f9a
Author: dz0ny <dz0ny@ubuntu.si>
Date: Sun May 4 19:48:34 2014 +0200
Add: HTTP tests for default router and static handler
commit 0d9544256bcb8f048eaedb5cdd57b1de027d387b
Author: dz0ny <dz0ny@ubuntu.si>
Date: Sun May 4 15:44:32 2014 +0200
Fix: Move StaticFileHandler to main http package
commit c83c9f661e658e4a843dc5c8c6ba5dc3f1ea9c1e
Author: dz0ny <dz0ny@ubuntu.si>
Date: Sun May 4 15:29:49 2014 +0200
Add: default Router implementation
commit 258cb7210bdf13833884c04cfb7fb4fa704394a7
Author: dz0ny <dz0ny@ubuntu.si>
Date: Sun May 4 15:00:46 2014 +0200
Add: Switch to registry for router registration
commit b7bfe7b814235b030d7ac30de90e2331e3d809d3
Author: dz0ny <dz0ny@ubuntu.si>
Date: Sat May 3 21:52:58 2014 +0200
Fix: Private methods
Fix: Point to mopidy.html instead main.html
Fix: Less noise in console
commit 232abe3029e93f78ce25db0c1bd44743cc23ed2d
Author: dz0ny <dz0ny@ubuntu.si>
Date: Sat May 3 21:32:07 2014 +0200
Fix: Start IOLoop in separate thread, so actor can stop it
commit d686892c2fa993cbedc99c8e8e7f9c961ac6f35a
Author: dz0ny <dz0ny@ubuntu.si>
Date: Sat May 3 19:30:49 2014 +0200
Fix: Router load order
Fix: JS helper library WSS default url
Add: Handlers from extensions
commit a1b0f5673a6719f229df27feccb284324675e9d1
Author: dz0ny <dz0ny@ubuntu.si>
Date: Sat May 3 14:53:30 2014 +0200
Add: Switch to Tornado framework
128 lines
4.3 KiB
ReStructuredText
128 lines
4.3 KiB
ReStructuredText
.. _ext-http:
|
|
|
|
***********
|
|
Mopidy-HTTP
|
|
***********
|
|
|
|
Mopidy-HTTP is an extension that lets you control Mopidy through HTTP and
|
|
WebSockets, for example from a web client. It is bundled with Mopidy and
|
|
enabled by default if all dependencies are available.
|
|
|
|
When it is enabled it starts a web server at the port specified by the
|
|
:confval:`http/port` config value.
|
|
|
|
.. warning::
|
|
|
|
As a simple security measure, the web server is by default only available
|
|
from localhost. To make it available from other computers, change the
|
|
:confval:`http/hostname` config value. Before you do so, note that the HTTP
|
|
extension does not feature any form of user authentication or
|
|
authorization. Anyone able to access the web server can use the full core
|
|
API of Mopidy. Thus, you probably only want to make the web server
|
|
available from your local network or place it behind a web proxy which
|
|
takes care or user authentication. You have been warned.
|
|
|
|
|
|
Using a web based Mopidy client
|
|
===============================
|
|
|
|
Mopidy-HTTP's web server can also host any static files, for example the HTML,
|
|
CSS, JavaScript, and images needed for a web based Mopidy client. To host
|
|
static files, change the :confval:`http/static_dir` config value to point to
|
|
the root directory of your web client, for example::
|
|
|
|
[http]
|
|
static_dir = /home/alice/dev/the-client
|
|
|
|
If the directory includes a file named ``index.html``, it will be served on the
|
|
root of Mopidy's web server.
|
|
|
|
If you're making a web based client and wants to do server side development as
|
|
well, you are of course free to run your own web server and just use Mopidy's
|
|
web server to host the API end points. But, for clients implemented purely in
|
|
JavaScript, letting Mopidy host the files is a simpler solution.
|
|
|
|
See :ref:`http-api` for details on how to integrate with Mopidy over HTTP. If
|
|
you're looking for a web based client for Mopidy, go check out
|
|
:ref:`http-clients`.
|
|
|
|
Extending server
|
|
================
|
|
|
|
If you wish to extend server additional service side functionality you must
|
|
create class that implements the :class:`mopidy.http.Router` interface and
|
|
install it in the extension registry under ``http:router``.
|
|
The default implementation already supports serving static files. If you just
|
|
want to serve static files you only need to define class variable :attr:`mopidy
|
|
.http.Router.name` and :attr:`mopidy.http.Router.path`, for example::
|
|
|
|
class WebClient(http.Router):
|
|
name = 'webclient'
|
|
path = os.path.join(os.path.dirname(__file__), 'public_html')
|
|
|
|
If you wish to extend server with custom methods you can override class method
|
|
``mopidy.http.Router.setup_routes`` and define custom routes.
|
|
|
|
|
|
Dependencies
|
|
============
|
|
|
|
In addition to Mopidy's dependencies, Mopidy-HTTP requires the following:
|
|
|
|
- tornado >= 3.1.1 Available as python-tornado in Debian/Ubuntu.
|
|
|
|
If you're installing Mopidy with pip, you can run the following command to
|
|
install Mopidy with the extra dependencies for required for Mopidy-HTTP::
|
|
|
|
pip install --upgrade Mopidy[http]
|
|
|
|
If you're installing Mopidy from APT, the additional dependencies needed for
|
|
Mopidy-HTTP are always included.
|
|
|
|
|
|
Configuration
|
|
=============
|
|
|
|
See :ref:`config` for general help on configuring Mopidy.
|
|
|
|
.. literalinclude:: ../../mopidy/http/ext.conf
|
|
:language: ini
|
|
|
|
.. confval:: http/enabled
|
|
|
|
If the HTTP extension should be enabled or not.
|
|
|
|
.. confval:: http/hostname
|
|
|
|
Which address the HTTP server should bind to.
|
|
|
|
``127.0.0.1``
|
|
Listens only on the IPv4 loopback interface
|
|
``::1``
|
|
Listens only on the IPv6 loopback interface
|
|
``0.0.0.0``
|
|
Listens on all IPv4 interfaces
|
|
``::``
|
|
Listens on all interfaces, both IPv4 and IPv6
|
|
|
|
.. confval:: http/port
|
|
|
|
Which TCP port the HTTP server should listen to.
|
|
|
|
.. confval:: http/static_dir
|
|
|
|
Which directory the HTTP server should serve at "/"
|
|
|
|
Change this to have Mopidy serve e.g. files for your JavaScript client.
|
|
"/mopidy" will continue to work as usual even if you change this setting.
|
|
|
|
.. confval:: http/zeroconf
|
|
|
|
Name of the HTTP service when published through Zeroconf. The variables
|
|
``$hostname`` and ``$port`` can be used in the name.
|
|
|
|
If set, the Zeroconf services ``_http._tcp`` and ``_mopidy-http._tcp`` will
|
|
be published.
|
|
|
|
Set to an empty string to disable Zeroconf for HTTP.
|