Skip to content

Commit

Permalink
🎨 Use SPA deployement
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianpb committed Mar 2, 2024
1 parent 0c1d3d6 commit 98475b4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
27 changes: 18 additions & 9 deletions mopidy_muse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,19 @@

logger = logging.getLogger(__name__)

class MuseRequestHandler(tornado.web.RequestHandler):
class SPARouterHandler(tornado.web.StaticFileHandler):
def initialize(self, path):
self.path = str(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)

class ConfigRouterHandler(tornado.web.RequestHandler):

def initialize(self, config):
muse_config = dict(config["muse"])
Expand All @@ -34,8 +46,12 @@ def get(self):
self.set_header('Content-Type', 'application/json')

def muse_factory(config, core):
path = pathlib.Path(__file__).parent / "static"

return [
('/config', MuseRequestHandler, {'config':config})
('/config', ConfigRouterHandler, {'config':config}),
(r"/((.*)(?:css|js|json|map|svg|png|jpg|ico)$)", tornado.web.StaticFileHandler, {"path": path}),
(r"/(.*)", SPARouterHandler, {"path": path / "index.html"})
]

class Extension(ext.Extension):
Expand All @@ -58,13 +74,6 @@ def get_config_schema(self):
return schema

def setup(self, registry):
registry.add(
"http:static",
{
"name": self.ext_name,
"path": str(pathlib.Path(__file__).parent / "static"),
},
)
registry.add('http:app', {
'name': self.ext_name,
'factory': muse_factory,
Expand Down
3 changes: 2 additions & 1 deletion src/routes/+layout.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// since there's no dynamic data here, we can prerender
// it so that it gets served as a static asset in production
export const prerender = true;
// SPA => only index.html is prerender
//export const prerender = true;
export const trailingSlash = "always";

0 comments on commit 98475b4

Please sign in to comment.