Add configurable bind address (#404)

This commit is contained in:
Flaminel
2025-12-31 04:40:43 +02:00
committed by GitHub
parent a708d22b27
commit b71b268b08
2 changed files with 29 additions and 5 deletions

View File

@@ -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<string>("PORT"), out int port);
port = port is 0 ? 11011 : port;
string? bindAddress = builder.Configuration.GetValue<string>("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();

View File

@@ -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 (
<SectionTitle>Port and Base Path (Non-Docker)</SectionTitle>
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
{