From 39b7fcbe94a6b738b22427d49f1108f88b624462 Mon Sep 17 00:00:00 2001 From: Marte Tassyns Date: Fri, 6 Dec 2024 13:46:35 +0000 Subject: [PATCH] fixed problem with ingress add-ons, tested using Advanced SSH & Web Terminal --- script/develop_and_serve | 11 ----------- script/serve.js | 38 +++++++++++++++++++++++++++++++++----- script/serve.pfx | Bin 0 -> 2651 bytes 3 files changed, 33 insertions(+), 16 deletions(-) create mode 100755 script/serve.pfx diff --git a/script/develop_and_serve b/script/develop_and_serve index 9d8e93650317..60837ae2c4e3 100755 --- a/script/develop_and_serve +++ b/script/develop_and_serve @@ -49,17 +49,6 @@ do esac done -# display used settings -if [ -n "$DEVCONTAINER" ]; then - echo Frontend is available inside container as http://localhost:${frontendPort} - if [ 8123 -eq $frontendPort ]; then - echo Frontend is available on container host as http://localhost:8124 - fi -else - echo Frontend is hosted on http://localhost:${frontendPort} -fi -echo Core is used from ${coreUrl} - if [ ! -d "./hassio/build" ]; then echo Building hassio # the hassio rest app doesn't need the HASS_URL override, diff --git a/script/serve.js b/script/serve.js index 038f6e2e8323..ef9c6097cca1 100644 --- a/script/serve.js +++ b/script/serve.js @@ -1,4 +1,6 @@ import express from "express"; +import https from "https"; +import fs from "fs"; import path from "path"; import { fileURLToPath } from "url"; @@ -12,6 +14,7 @@ import { createProxyMiddleware } from "http-proxy-middleware"; const coreProxy = createProxyMiddleware({ target: coreUrl, changeOrigin: true, + ws: true, }); const app = express(); @@ -22,13 +25,38 @@ app.get("*", (req, res) => { res.sendFile(path.join(repoDir, "hass_frontend/index.html")); }); -var server = app.listen(port, () => { - console.log( - `Running at http://localhost:${port}, connected to core on ${coreUrl}` - ); +// if the core uses https, also use https for serving to avoid problems +// with headers like Strict-Transport-Security +const useHttps = coreUrl.startsWith("https:"); + +const appServer = useHttps + ? https.createServer( + { + pfx: fs.readFileSync(repoDir + "/script/serve.pfx"), + passphrase: "localhost", + }, + app + ) + : app; + +const frontendBase = `http${useHttps ? "s" : ""}://localhost`; +appServer.listen(port, () => { + if (process.env.DEVCONTAINER !== undefined) { + console.log( + `Frontend is available inside container as ${frontendBase}:${port}` + ); + if (port === 8123) { + console.log( + `Frontend is available on container host as ${frontendBase}://localhost:8124` + ); + } + } else { + console.log(`Frontend is hosted on ${frontendBase}:${port}`); + } + console.log(`Core is used from ${coreUrl}`); }); process.on("SIGINT", function () { console.log("Shutting down file server"); - server.close(); + process.exit(0); }); diff --git a/script/serve.pfx b/script/serve.pfx new file mode 100755 index 0000000000000000000000000000000000000000..a33ea464f44a6651fb13d2535e2c94306479a94d GIT binary patch literal 2651 zcmZWpXH=8f7X3ni(3=R6UX>OSYG?|EE{Ig61x0!nhM@!y2uSbJB!IvWrFWG!NCc#b zw4q56klr0S26!3QyqWdZ`*HR@XYYH?y1zC8OJhz30wb_Atd!JZQ94n_^dJbR082wb zj->%1u+--WEXB_MSQKB$u@uuJd4g1HKO_GMqUKLyU4V z7liF=H!f5@F0HcPRy~#JOXu($v!A^7asYpwDE&0_6|ywe`eyHmrO&iA@=`27Q9wf` z`Ez`_Fy3 z*DvnhIScyG_Esql&lL57zMVEbEarz9zB`a_X{_xxwAuF}(V-nPB6YD)#OhTgC z_xI4c00!lwx#zTN?a$+ML>nCwKaDnw{vN%lD9)HXW694Dw%Xqn9m>bAk6C~6|?ro#Mv#W4GKFX~rmWK@JTbaE9{&t^Um`uk({ z{CCvXuq~Vt7JOF14to!hrSV$uYf!5SY5R;p0WOsthMGu0+a$qr1%EW+GFqmW7c}c4~adz4)g5_^SO(LcFM%& zN2Ak!S}X*29V?zcaBc7_c=pAQd{^J2kUPA9ZyWxBY{fk7P&FlfY~hWN-!99inuG4E zQRX~eJ9;h!p?V1@2J_2hKc5B~JCQG=j3C2Z$2nu=>@c7EL`ic;O(Y_&3c4uYl1Hn@Yt#CCHiXlA zETv3EiD9A3E=GO?f;?Uc!vE%%r{*GE1HEkOX=scqVHUT9Vk&Y!2J9RT9D?nvz3;v8 zbQxj9)y9_fNH>cPTSpTl6b7pt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