From b71b268b08b8dd274a00b0ca3cc15f46f4e9ed95 Mon Sep 17 00:00:00 2001 From: Flaminel Date: Wed, 31 Dec 2025 04:40:43 +0200 Subject: [PATCH] Add configurable bind address (#404) --- code/backend/Cleanuparr.Api/Program.cs | 19 ++++++++++++++++--- docs/docs/installation/detailed.mdx | 15 +++++++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/code/backend/Cleanuparr.Api/Program.cs b/code/backend/Cleanuparr.Api/Program.cs index ab5a3b0b..d1fc150a 100644 --- a/code/backend/Cleanuparr.Api/Program.cs +++ b/code/backend/Cleanuparr.Api/Program.cs @@ -1,3 +1,4 @@ +using System.Net; using System.Runtime.InteropServices; using System.Text.Json.Serialization; using Cleanuparr.Api; @@ -33,12 +34,24 @@ builder.Configuration int.TryParse(builder.Configuration.GetValue("PORT"), out int port); port = port is 0 ? 11011 : port; +string? bindAddress = builder.Configuration.GetValue("BIND_ADDRESS"); + if (!builder.Environment.IsDevelopment()) { - // If no port is configured, default to 11011 builder.WebHost.ConfigureKestrel(options => { - options.ListenAnyIP(port); + if (string.IsNullOrEmpty(bindAddress) || bindAddress is "0.0.0.0" || bindAddress is "*") + { + options.ListenAnyIP(port); + } + else if (IPAddress.TryParse(bindAddress, out var ipAddress)) + { + options.Listen(ipAddress, port); + } + else + { + throw new ArgumentException($"Invalid BIND_ADDRESS: '{bindAddress}'"); + } }); } @@ -124,7 +137,7 @@ if (basePath is not null) } } -logger.LogInformation("Server configuration: PORT={port}, BASE_PATH={basePath}", port, basePath ?? "/"); +logger.LogInformation("Server configuration: BIND_ADDRESS={bindAddress}, PORT={port}, BASE_PATH={basePath}", bindAddress ?? "0.0.0.0", port, basePath ?? "/"); // Initialize the host app.Init(); diff --git a/docs/docs/installation/detailed.mdx b/docs/docs/installation/detailed.mdx index 76e60679..33c41b59 100644 --- a/docs/docs/installation/detailed.mdx +++ b/docs/docs/installation/detailed.mdx @@ -96,6 +96,7 @@ services: | Variable | Default | Description | |----------|---------|-------------| | `PORT` | 11011 | Port for the web interface | +| `BIND_ADDRESS` | 0.0.0.0 | IP address to bind to | | `BASE_PATH` | *(empty)* | Base path for reverse proxy setups ([examples](#example-configurations)) | | `PUID` | 1000 | User ID for file permissions | | `PGID` | 1000 | Group ID for file permissions | @@ -277,6 +278,7 @@ To run Cleanuparr as a systemd service: Restart=always RestartSec=5 Environment=PORT=11011 + Environment=BIND_ADDRESS=0.0.0.0 Environment=BASE_PATH= [Install] @@ -330,7 +332,7 @@ To change the port or base path for AUR installations, see [Port and Base Path ( Port and Base Path (Non-Docker) -For all non-Docker installations (Windows, macOS, Linux portable), you can configure the PORT and BASE_PATH by creating a configuration file. +For all non-Docker installations (Windows, macOS, Linux portable), you can configure the PORT, BIND_ADDRESS and BASE_PATH by creating a configuration file. ### Initial Setup @@ -347,6 +349,7 @@ For all non-Docker installations (Windows, macOS, Linux portable), you can confi ```json { "PORT": 11011, + "BIND_ADDRESS": "0.0.0.0", "BASE_PATH": "" } ``` @@ -358,11 +361,19 @@ For all non-Docker installations (Windows, macOS, Linux portable), you can confi **Running on port 8080:** ```json { - "PORT": 8080, + "PORT": 8080 } ``` Access via: `http://localhost:8080` +**Binding to localhost only:** +```json +{ + "BIND_ADDRESS": "127.0.0.1" +} +``` +Only accessible from the local machine. + **Running with reverse proxy at `/cleanuparr`:** ```json {