Skip to content

Commit

Permalink
fixed problem with ingress add-ons, tested using Advanced SSH & Web T…
Browse files Browse the repository at this point in the history
…erminal
  • Loading branch information
martetassyns committed Dec 6, 2024
1 parent b6ca770 commit 39b7fcb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
11 changes: 0 additions & 11 deletions script/develop_and_serve
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
38 changes: 33 additions & 5 deletions script/serve.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import express from "express";
import https from "https";
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";

Expand All @@ -12,6 +14,7 @@ import { createProxyMiddleware } from "http-proxy-middleware";
const coreProxy = createProxyMiddleware({
target: coreUrl,
changeOrigin: true,
ws: true,
});

const app = express();
Expand All @@ -22,13 +25,38 @@ app.get("*", (req, res) => {
res.sendFile(path.join(repoDir, "hass_frontend/index.html"));
});

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
a file system access
, but is not rate-limited.

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);
});
Binary file added script/serve.pfx
Binary file not shown.

0 comments on commit 39b7fcb

Please sign in to comment.