From 70001af2ba2bd89f8e10d0ce1707fc67620950c1 Mon Sep 17 00:00:00 2001 From: Claas Augner <495429+caugner@users.noreply.github.com> Date: Thu, 10 Oct 2024 14:58:52 +0200 Subject: [PATCH] enhance(server): introduce SERVER_HOST variable (#11394) --- docs/envvars.md | 6 ++++++ server/index.ts | 5 +++-- server/static.ts | 5 ++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/docs/envvars.md b/docs/envvars.md index 0d70412bb960..128ab565590f 100644 --- a/docs/envvars.md +++ b/docs/envvars.md @@ -193,6 +193,12 @@ Flaw types to be fixed when running `fix-flaws`. ## Server +### `SERVER_HOST` + +**Default: (undefined)** + +Set this to `0.0.0.0` to access the server from a different local device. + ### `SERVER_PORT` **Default: `5042`** diff --git a/server/index.ts b/server/index.ts index fd5fe42929c2..eef2a64f81e5 100644 --- a/server/index.ts +++ b/server/index.ts @@ -463,9 +463,10 @@ console.log( : "" ); +const HOST = process.env.SERVER_HOST || undefined; const PORT = parseInt(process.env.SERVER_PORT || "5042"); -app.listen(PORT, () => { - console.log(`Listening on port ${PORT}`); +app.listen(PORT, HOST, () => { + console.log(`Listening on ${HOST ? `${HOST}:` : "port "}${PORT}`); if (process.env.EDITOR) { console.log(`Your EDITOR is set to: ${chalk.bold(process.env.EDITOR)}`); } else { diff --git a/server/static.ts b/server/static.ts index a3519ca254d6..243834204f58 100644 --- a/server/static.ts +++ b/server/static.ts @@ -253,5 +253,8 @@ app.get("/*", async (req, res) => { .sendFile(path.join(STATIC_ROOT, "en-us", "_spas", "404.html")); }); +const HOST = process.env.SERVER_HOST || undefined; const PORT = parseInt(process.env.SERVER_PORT || "5042"); -app.listen(PORT, () => console.log(`Listening on port ${PORT}`)); +app.listen(PORT, HOST, () => + console.log(`Listening on ${HOST ? `${HOST}:` : "port "}${PORT}`) +);