Fix Extension setup and factory import.
Moved ReactRouterHandler to be with the other handlers
This commit is contained in:
@ -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'
|
||||
}
|
||||
),
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user