include frontend app (again)
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Sat, 19 Dec 2020 19:08:47 +0000 (20:08 +0100)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Sat, 19 Dec 2020 19:08:47 +0000 (20:08 +0100)
Dockerfile
music_assistant/constants.py
music_assistant/mass.py
music_assistant/web/server.py

index f03e2470bfd4b8060c24a36bb1ef6329ad07200d..04c6371cdb67b17ee15904741f126582b2e74fc7 100644 (file)
@@ -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
index 33983315ee5358e3ae3ae356033d53ada05c6114..f16216816dc3ce5e5afb62c38c444c6b7f3d4086 100755 (executable)
@@ -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
index 791810367b0f9e4fec60c08ad4a6b074d4d86089..0823fc6d393c0402977c68cf259b3aa240e06de8 100644 (file)
@@ -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:
index 1d3f7b779f07daef8df8621fcff11a397a85dd99..67dcc4bde07eb93d9596bd1880acda7ccbcc3078 100755 (executable)
@@ -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."""