mirror of
https://github.com/Cleanuparr/Cleanuparr.git
synced 2026-05-19 03:55:52 -04:00
Add configurable bind address (#404)
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user