diff --git a/mediahive/__main__.py b/mediahive/__main__.py index 1f33c01..78e7e3b 100644 --- a/mediahive/__main__.py +++ b/mediahive/__main__.py @@ -6,7 +6,7 @@ from pathlib import Path from fastapi_vue import server DEFAULT_PORT = 8420 -DEVMODE = bool(os.getenv("MEDIAHIVE_FRONTEND_URL")) +DEVMODE = os.getenv("MEDIAHIVE_DEV") == "1" def resolve_media_root(path: str | None = None) -> Path: diff --git a/scripts/devserver.py b/scripts/devserver.py index d11bfdd..9894e0a 100644 --- a/scripts/devserver.py +++ b/scripts/devserver.py @@ -1,6 +1,6 @@ #!/usr/bin/env -S uv run # auto-upgrade@fastapi-vue-setup - remove this if you modify this file -"""Run Vite development server for frontend and FastAPI backend with auto-reload.""" +"""Run Vite development server for Vue app and FastAPI backend with auto-reload.""" import argparse import asyncio @@ -25,7 +25,7 @@ DEFAULT_DEV_PORT = 8421 async def run_devserver( - frontend: str, backend: str, extra_args: list[str] | None = None + listen: str, backend: str, extra_args: list[str] | None = None ) -> None: reporoot = Path(__file__).parent.parent front = reporoot / "frontend" @@ -33,12 +33,13 @@ async def run_devserver( logger.warning("Frontend source not found at %s", front) raise SystemExit(1) - viteurl, npm_install, vite = setup_vite(frontend, DEFAULT_VITE_PORT) + viteurl, npm_install, vite = setup_vite(listen, DEFAULT_VITE_PORT) backurl, mediahive = setup_cli("mediahive", backend, DEFAULT_DEV_PORT) - # Tell the everyone where the frontend and backend are (vite proxy, etc) - os.environ["MEDIAHIVE_FRONTEND_URL"] = viteurl + # Tell the everyone by environment (vite proxy and backend devmode use these) + os.environ["MEDIAHIVE_VITE_URL"] = viteurl os.environ["MEDIAHIVE_BACKEND_URL"] = backurl + os.environ["MEDIAHIVE_DEV"] = "1" async with ProcessGroup() as pg: npm_i = await pg.spawn(*npm_install, cwd=front) @@ -55,19 +56,19 @@ def main(): epilog=HELP_EPILOG, ) parser.add_argument( - "frontend", - nargs="?", + "-l", + "--listen", metavar="host:port", - help=f"Vite frontend endpoint (default: localhost:{DEFAULT_VITE_PORT})", + help=f"Vite (default: localhost:{DEFAULT_VITE_PORT})", ) parser.add_argument( "--backend", metavar="host:port", - help=f"FastAPI backend endpoint (default: localhost:{DEFAULT_DEV_PORT})", + help=f"FastAPI (default: localhost:{DEFAULT_DEV_PORT})", ) args, extra_args = parser.parse_known_args() with suppress(KeyboardInterrupt): - asyncio.run(run_devserver(args.frontend, args.backend, extra_args)) + asyncio.run(run_devserver(args.listen, args.backend, extra_args)) HELP_EPILOG = """ diff --git a/scripts/fastapi-vue/devutil.py b/scripts/fastapi-vue/devutil.py index 66c4744..9a82d25 100644 --- a/scripts/fastapi-vue/devutil.py +++ b/scripts/fastapi-vue/devutil.py @@ -9,9 +9,10 @@ from pathlib import Path from typing import Any import httpx -from buildutil import find_dev_tool, find_install_tool, logger from fastapi_vue.hostutil import parse_endpoint +from buildutil import find_dev_tool, find_install_tool, logger + class ProcessGroup: """Manage async subprocesses with automatic cleanup, like TaskGroup for processes."""