diff --git a/mopidy_iris/__init__.py b/mopidy_iris/__init__.py index 57ad8f7c..69ce9fdb 100755 --- a/mopidy_iris/__init__.py +++ b/mopidy_iris/__init__.py @@ -1,13 +1,7 @@ import logging, json, pathlib -import tornado.web -import tornado.websocket import pkg_resources from mopidy import config, ext -from .frontend import IrisFrontend -from .handlers import WebsocketHandler, HttpHandler -from .core import IrisCore -from .mem import iris __version__ = pkg_resources.get_distribution("Mopidy-Iris").version @@ -40,7 +34,7 @@ class Extension( ext.Extension ): return schema def setup(self, registry): - + from .frontend import IrisFrontend # Add web extension registry.add('http:app', { 'name': self.ext_name, @@ -50,33 +44,19 @@ class Extension( ext.Extension ): # Add our frontend registry.add('frontend', IrisFrontend) -## -# Customised handler for react router URLS -# -# This routes all URLs to the same path, so that React can handle the path etc -## -class ReactRouterHandler(tornado.web.StaticFileHandler): - def initialize(self, path): - self.path = path - self.absolute_path = path - self.dirname = path.parent - self.filename = path.name - super().initialize(self.dirname) - - def get(self, path=None, include_body=True): - return super().get(self.path, include_body) - ## # Frontend factory ## def iris_factory(config, core): + from tornado.web import StaticFileHandler + from .handlers import HttpHandler, ReactRouterHandler, WebsocketHandler path = pathlib.Path(__file__).parent / 'static' return [ ( r'/http/([^/]*)', - handlers.HttpHandler, + HttpHandler, { 'core': core, 'config': config @@ -84,7 +64,7 @@ def iris_factory(config, core): ), ( r'/ws/?', - handlers.WebsocketHandler, + WebsocketHandler, { 'core': core, 'config': config @@ -92,21 +72,22 @@ def iris_factory(config, core): ), ( r'/assets/(.*)', - tornado.web.StaticFileHandler, + StaticFileHandler, { 'path': path / 'assets' } ), ( r'/((.*)(?:css|js|json|map)$)', - tornado.web.StaticFileHandler, + StaticFileHandler, { 'path': path } ), ( r'/(.*)', - ReactRouterHandler, { + ReactRouterHandler, + { 'path': path / 'index.html' } ), diff --git a/mopidy_iris/handlers.py b/mopidy_iris/handlers.py index ecb54d67..18f327c1 100755 --- a/mopidy_iris/handlers.py +++ b/mopidy_iris/handlers.py @@ -233,4 +233,19 @@ class HttpHandler(tornado.web.RequestHandler): self.finish() +## +# Customised handler for react router URLS +# +# This routes all URLs to the same path, so that React can handle the path etc +## +class ReactRouterHandler(tornado.web.StaticFileHandler): + def initialize(self, path): + self.path = path + self.absolute_path = path + self.dirname = path.parent + self.filename = path.name + super().initialize(self.dirname) + + def get(self, path=None, include_body=True): + return super().get(self.path, include_body)