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 000000000000..a33ea464f44a Binary files /dev/null and b/script/serve.pfx differ