From 500d655ba631bdbffc53885d8738cb949804fd2d Mon Sep 17 00:00:00 2001 From: Marte Tassyns Date: Fri, 6 Dec 2024 15:19:14 +0000 Subject: [PATCH] made it easier to serve an existing build without using develop_and_serve --- package.json | 1 + script/develop_and_serve | 21 +-------------------- script/serve.js | 13 ++++++++++--- 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index 522bd52a3b43..fde4ef552e9d 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "postinstall": "husky", "prepack": "pinst --disable", "postpack": "pinst --enable", + "serve": "node ./script/serve.js", "test": "vitest run --config test/vitest.config.ts", "test:coverage": "vitest run --config test/vitest.config.ts --coverage" }, diff --git a/script/develop_and_serve b/script/develop_and_serve index ef0cd18a6707..eab009eb8d02 100755 --- a/script/develop_and_serve +++ b/script/develop_and_serve @@ -34,25 +34,6 @@ set -e cd "$(dirname "$0")/.." -# parse input paramters -if [ -n "$DEVCONTAINER" ]; then - frontendPort=8123 -else - frontendPort=8124 -fi - -coreUrl=http://localhost:8123 - -while getopts p:c:h flag -do - case "${flag}" in - p) frontendPort=${OPTARG};; - c) coreUrl="${OPTARG}";; - h) echo Documentation can be found inside "$0" && exit 0;; - *) echo Documentation can be found inside "$0" && exit 1;; - esac -done - if [ ! -d "./hassio/build" ]; then echo Building hassio # the hassio rest app doesn't need the HASS_URL override, @@ -67,4 +48,4 @@ if [ -n "$DEVCONTAINER" ]; then else nodeCoreUrl="$coreUrl" fi -yarn exec node ./script/serve.js "$nodeCoreUrl" $frontendPort \ No newline at end of file +yarn serve "$@" \ No newline at end of file diff --git a/script/serve.js b/script/serve.js index ec1ced20e1f0..9ad5a77dfa33 100644 --- a/script/serve.js +++ b/script/serve.js @@ -1,11 +1,18 @@ import express from "express"; import https from "https"; import fs from "fs"; +import minimist from "minimist"; import path from "path"; import { fileURLToPath } from "url"; -const coreUrl = process.argv[2]; -const port = parseInt(process.argv[3] ?? "8123"); +const parsedArguments = { + c: "http://localhost:8123", + p: process.env.DEVCONTAINER !== undefined ? "8123" : "8124", + ...minimist(process.argv.slice(2)), +}; + +const coreUrl = parsedArguments.c; +const port = parseInt(parsedArguments.p); const repoDir = path.join(fileURLToPath(import.meta.url), "../.."); @@ -55,7 +62,7 @@ appServer.listen(port, () => { ); if (port === 8123) { console.log( - `Frontend is available on container host as ${frontendBase}://localhost:8124` + `Frontend is available on container host as ${frontendBase}:8124` ); } } else {