From 72c12ed078ee3cb962ae49fafe4765d2cc871b38 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Sat, 19 Dec 2020 20:08:47 +0100 Subject: [PATCH] include frontend app (again) --- Dockerfile | 3 +++ music_assistant/constants.py | 2 +- music_assistant/mass.py | 2 +- music_assistant/web/server.py | 27 +++++++++++++++++++++++---- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index f03e2470..04c6371c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,6 +33,9 @@ WORKDIR /wheels COPY . /tmp RUN pip wheel uvloop cchardet aiodns brotlipy \ && pip wheel -r /tmp/requirements.txt \ + # Include frontend-app in the source files + && curl -L https://github.com/music-assistant/app/archive/master.tar.gz | tar xz \ + && mv app-master/docs /tmp/music_assistant/web/static \ && pip wheel /tmp #### FINAL IMAGE diff --git a/music_assistant/constants.py b/music_assistant/constants.py index 33983315..f1621681 100755 --- a/music_assistant/constants.py +++ b/music_assistant/constants.py @@ -1,6 +1,6 @@ """All constants for Music Assistant.""" -__version__ = "0.0.74" +__version__ = "0.0.75" REQUIRED_PYTHON_VER = "3.7" # configuration keys/attributes diff --git a/music_assistant/mass.py b/music_assistant/mass.py index 79181036..0823fc6d 100644 --- a/music_assistant/mass.py +++ b/music_assistant/mass.py @@ -333,7 +333,7 @@ class MusicAssistant: addresses=[get_ip_pton()], port=self.web.port, properties=self.web.discovery_info, - server="musicassistant.local.", + server=f"mass_{self.web.server_id}.local.", ) LOGGER.debug("Starting Zeroconf broadcast...") try: diff --git a/music_assistant/web/server.py b/music_assistant/web/server.py index 1d3f7b77..67dcc4bd 100755 --- a/music_assistant/web/server.py +++ b/music_assistant/web/server.py @@ -78,7 +78,7 @@ class WebServer: ]: self.register_api_routes(cls) - # Add server discovery on root/index including CORS support + # Add server discovery on info including CORS support cors = aiohttp_cors.setup( self.app, defaults={ @@ -88,7 +88,14 @@ class WebServer: ) }, ) - cors.add(self.app.router.add_get("/", self.async_info)) + cors.add(self.app.router.add_get("/info", self.async_info)) + # Host the frontend app + webdir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "static/") + if os.path.isdir(webdir): + self.app.router.add_get("/", self.async_index) + self.app.router.add_static("/", webdir, append_version=True) + else: + self.app.router.add_get("/", self.async_info) self._runner = web.AppRunner(self.app, access_log=None) await self._runner.setup() @@ -121,8 +128,8 @@ class WebServer: def hostname(self): """Return the hostname for this Music Assistant instance.""" if not self._hostname.endswith(".local"): - # probably running in docker ? - return "musicassistant.local" + # probably running in docker, use mdns name instead + return f"mass_{self.server_id}.local" return self._hostname @property @@ -165,6 +172,18 @@ class WebServer: "initialized": self.mass.config.stored_config["initialized"], } + async def async_index(self, request: web.Request): + """Get the index page, redirect if we do not have a web directory.""" + # pylint: disable=unused-argument + if not self.mass.config.stored_config["initialized"]: + return web.FileResponse( + os.path.join(os.path.dirname(os.path.abspath(__file__)), "setup.html") + ) + html_app = os.path.join( + os.path.dirname(os.path.abspath(__file__)), "static/index.html" + ) + return web.FileResponse(html_app) + @api_route("info", False) async def async_info(self, request: web.Request = None): """Return discovery info on index page.""" -- 2.34.1