From 1302d339341074cee5f004de3b7c651f6b8b30c3 Mon Sep 17 00:00:00 2001 From: Dean Lawrence Date: Sun, 12 May 2024 00:46:23 -0400 Subject: [PATCH] Added function to set magma .env when using build flag --- server.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/server.py b/server.py index 3637d6197..2e3a4eab6 100644 --- a/server.py +++ b/server.py @@ -37,6 +37,9 @@ from app.utility.config_generator import ensure_local_config +MAGMA_PATH = "./plugins/magma" + + def setup_logger(level=logging.DEBUG): format = "%(message)s" datefmt = "%Y-%m-%d %H:%M:%S" @@ -139,11 +142,19 @@ async def enable_cors(request, response): async def start_vue_dev_server(): await asyncio.create_subprocess_shell( - "npm run dev", stdout=sys.stdout, stderr=sys.stderr, cwd="./plugins/magma/" + "npm run dev", stdout=sys.stdout, stderr=sys.stderr, cwd=MAGMA_PATH ) logging.info("VueJS development server is live.") +def configure_magma_env_file(): + logging.info("Setting VueJS environment file.") + host = BaseWorld.get_config("host") + port = BaseWorld.get_config("port") + with open("%s/.env" % MAGMA_PATH, "w") as fp: + fp.write("VITE_CALDERA_URL=http://%s:%s" % (host, port)) + + def _get_parser(): def list_str(values): @@ -251,19 +262,20 @@ def list_str(values): app_svc.register_subapp("/api/v2", app.api.v2.make_app(app_svc.get_services())) init_swagger_documentation(app_svc.application) if args.uiDevHost: - if not os.path.exists("./plugins/magma/dist"): + if not os.path.exists("%s/dist" % MAGMA_PATH): logging.info("Building VueJS front-end.") - subprocess.run(["npm", "run", "build"], cwd="plugins/magma", check=True) + subprocess.run(["npm", "run", "build"], cwd=MAGMA_PATH, check=True) logging.info("VueJS front-end build complete.") app_svc.application.on_response_prepare.append(enable_cors) if args.build: + configure_magma_env_file() logging.info("Building VueJS front-end.") - subprocess.run(["npm", "install"], cwd="plugins/magma", check=True) - subprocess.run(["npm", "run", "build"], cwd="plugins/magma", check=True) + subprocess.run(["npm", "install"], cwd=MAGMA_PATH, check=True) + subprocess.run(["npm", "run", "build"], cwd=MAGMA_PATH, check=True) logging.info("VueJS front-end build complete.") else: - if not os.path.exists("./plugins/magma/dist"): + if not os.path.exists("%s/dist" % MAGMA_PATH): logging.warning( "[bright_yellow]Built Caldera v5 Vue components not detected, and `--build` flag not supplied." " If attempting to start Caldera v5 for the first time, the `--build` flag must be"