From b0253e11bfbef37644a8f85ee20c135e428e059e Mon Sep 17 00:00:00 2001 From: Kukks Date: Thu, 18 Aug 2022 13:12:29 +0200 Subject: [PATCH] Revert "Allow bind and port for http too (#4031)" This reverts commit a51c9d2b2dfd1b78ce99cb9c527f17a559660e43. --- BTCPayServer/Hosting/Startup.cs | 53 ++++++++------------- BTCPayServer/Properties/launchSettings.json | 6 +-- 2 files changed, 23 insertions(+), 36 deletions(-) diff --git a/BTCPayServer/Hosting/Startup.cs b/BTCPayServer/Hosting/Startup.cs index 8d7b7d050..c2230ea7b 100644 --- a/BTCPayServer/Hosting/Startup.cs +++ b/BTCPayServer/Hosting/Startup.cs @@ -167,53 +167,40 @@ namespace BTCPayServer.Hosting bool hasCertPath = !String.IsNullOrEmpty(httpsCertificateFilePath); services.Configure(kestrel => { - kestrel.Limits.MaxRequestLineSize = - 8_192 * 10 * 5; // Around 500K, transactions passed in URI should not be bigger than this + kestrel.Limits.MaxRequestLineSize = 8_192 * 10 * 5; // Around 500K, transactions passed in URI should not be bigger than this + }); + if (hasCertPath || useDefaultCertificate) + { + var bindAddress = Configuration.GetOrDefault("bind", IPAddress.Any); + int bindPort = Configuration.GetOrDefault("port", 443); - var bindAddress = Configuration.GetOrDefault("bind", null); - int? bindPort = Configuration.GetOrDefault("port", -1); - bindPort = bindPort == -1 ? null : bindPort; - if (hasCertPath || useDefaultCertificate) + services.Configure(kestrel => { - bindAddress ??= IPAddress.Any; - bindPort ??= 443; if (hasCertPath && !File.Exists(httpsCertificateFilePath)) { // Note that by design this is a fatal error condition that will cause the process to exit. - throw new ConfigException( - $"The https certificate file could not be found at {httpsCertificateFilePath}."); + throw new ConfigException($"The https certificate file could not be found at {httpsCertificateFilePath}."); } - if (hasCertPath && useDefaultCertificate) { - throw new ConfigException( - $"Conflicting settings: if HttpsUseDefaultCertificate is true, HttpsCertificateFilePath should not be used"); + throw new ConfigException($"Conflicting settings: if HttpsUseDefaultCertificate is true, HttpsCertificateFilePath should not be used"); } - } - if (bindAddress is not null && bindPort is not null) - { - - kestrel.Listen(bindAddress, bindPort.Value, l => + kestrel.Listen(bindAddress, bindPort, l => { - if (hasCertPath || useDefaultCertificate) + if (hasCertPath) { - if (hasCertPath) - { - Logs.Configuration.LogInformation( - $"Using HTTPS with the certificate located in {httpsCertificateFilePath}."); - l.UseHttps(httpsCertificateFilePath, - Configuration.GetOrDefault("HttpsCertificateFilePassword", null)); - } - else - { - Logs.Configuration.LogInformation($"Using HTTPS with the default certificate"); - l.UseHttps(); - } + Logs.Configuration.LogInformation($"Using HTTPS with the certificate located in {httpsCertificateFilePath}."); + l.UseHttps(httpsCertificateFilePath, Configuration.GetOrDefault("HttpsCertificateFilePassword", null)); + } + else + { + Logs.Configuration.LogInformation($"Using HTTPS with the default certificate"); + l.UseHttps(); } }); - } - }); + }); + } } public void Configure( IApplicationBuilder app, diff --git a/BTCPayServer/Properties/launchSettings.json b/BTCPayServer/Properties/launchSettings.json index 460c6fa6f..d9550f935 100644 --- a/BTCPayServer/Properties/launchSettings.json +++ b/BTCPayServer/Properties/launchSettings.json @@ -31,7 +31,7 @@ "BTCPAY_CHEATMODE": "true", "BTCPAY_EXPLORERPOSTGRES": "User ID=postgres;Include Error Detail=true;Host=127.0.0.1;Port=39372;Database=nbxplorer" }, - "applicationUrl": "http://localhost:14142/" + "applicationUrl": "http://0.0.0.0:14142/" }, "Bitcoin-HTTPS": { "commandName": "Project", @@ -68,7 +68,7 @@ "BTCPAY_CHEATMODE": "true", "BTCPAY_EXPLORERPOSTGRES": "User ID=postgres;Include Error Detail=true;Host=127.0.0.1;Port=39372;Database=nbxplorer" }, - "applicationUrl": "https://localhost:14142/" + "applicationUrl": "https://0.0.0.0:14142/" }, "Altcoins-HTTPS": { "commandName": "Project", @@ -107,7 +107,7 @@ "BTCPAY_CHEATMODE": "true", "BTCPAY_EXPLORERPOSTGRES": "User ID=postgres;Include Error Detail=true;Host=127.0.0.1;Port=39372;Database=nbxplorer" }, - "applicationUrl": "https://localhost:14142/" + "applicationUrl": "https://0.0.0.0:14142/" } } }