Make proxy port configurable

This commit is contained in:
pcjones
2025-01-13 19:35:30 +01:00
parent f916aa3761
commit 275f29ec11
5 changed files with 23 additions and 25 deletions

View File

@@ -20,5 +20,12 @@
/// </summary>
public int IndexerRequestsCacheDurationInMinutes { get; set; } = 12;
/// <summary>
/// API key for requests to the UmlautAdaptarr. Optional.
public string? ApiKey { get; set; } = null;
/// <summary>
/// Proxy port for the internal UmlautAdaptarr proxy.
public int ProxyPort { get; set; } = 5006;
}
}

View File

@@ -8,7 +8,8 @@ using UmlautAdaptarr.Utilities;
internal class Program
{
private static void Main(string[] args) {
private static void Main(string[] args)
{
MainAsync(args).Wait();
}
@@ -22,11 +23,6 @@ internal class Program
builder.Services.AddSerilog();
// Log all configuration values
LogConfigurationValues(configuration);
// Add services to the container.
builder.Services.AddHttpClient("HttpClient").ConfigurePrimaryHttpMessageHandler(() =>
{
@@ -123,15 +119,4 @@ internal class Program
//.Enrich.With(new ApiKeyMaskingEnricher("appsettings.json")) // TODO - Not working currently
.CreateLogger();
}
private static void LogConfigurationValues(IConfiguration configuration)
{
Log.Information("Logging all configuration values at startup:");
foreach (var kvp in configuration.AsEnumerable())
{
Log.Information("{Key}: {Value}", kvp.Key, kvp.Value);
}
}
}

View File

@@ -3,7 +3,8 @@
"http": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
"ASPNETCORE_ENVIRONMENT": "Development",
"Kestrel__Endpoints__Http__Url": "http://[::]:8080"
},
"_launchUrl": "optionsTODO/example.com/api?t=movie&apikey=132&imdbid=123&limit=100",
"dotnetRunMessages": true,

View File

@@ -1,6 +1,8 @@
using System.Net;
using Microsoft.Extensions.Options;
using System.Net;
using System.Net.Sockets;
using System.Text;
using UmlautAdaptarr.Options;
namespace UmlautAdaptarr.Services
{
@@ -8,15 +10,16 @@ namespace UmlautAdaptarr.Services
{
private TcpListener _listener;
private readonly ILogger<HttpProxyService> _logger;
private readonly int _proxyPort = 5006; // TODO move to appsettings.json
private readonly IHttpClientFactory _clientFactory;
private readonly GlobalOptions _options;
private readonly HashSet<string> _knownHosts = [];
private readonly object _hostsLock = new();
private readonly IConfiguration _configuration;
private static readonly string[] newLineSeparator = ["\r\n"];
public HttpProxyService(ILogger<HttpProxyService> logger, IHttpClientFactory clientFactory, IConfiguration configuration)
public HttpProxyService(ILogger<HttpProxyService> logger, IHttpClientFactory clientFactory, IConfiguration configuration, IOptions<GlobalOptions> options)
{
_options = options.Value;
_logger = logger;
_configuration = configuration;
_clientFactory = clientFactory;
@@ -168,7 +171,7 @@ namespace UmlautAdaptarr.Services
public Task StartAsync(CancellationToken cancellationToken)
{
_listener = new TcpListener(IPAddress.Any, _proxyPort);
_listener = new TcpListener(IPAddress.Any, _options.ProxyPort);
_listener.Start();
Task.Run(() => HandleRequests(cancellationToken), cancellationToken);
return Task.CompletedTask;

View File

@@ -35,6 +35,8 @@ services:
### Advanced options (with default values))
#- IpLeakTest__Enabled=false
#- SETTINGS__IndexerRequestsCacheDurationInMinutes=12
#- Kestrel__Endpoints__Http__Url=http://[::]:8080
#- SETTINGS__IndexerRequestsCacheDurationInMinutes=12 # How long to cache indexer requests for. Default is 12 minutes.
#- SETTINGS__ApiKey= # API key for requests to the UmlautAdaptarr. Optional, probably only needed for seedboxes.
#- SETTINGS__ProxyPort=5006 # Proxy port for the internal UmlautAdaptarr proxy used for Prowlarr.
#- Kestrel__Endpoints__Http__Url=http://[::]:5005 # HTTP port for the UmlautAdaptarr