Compare commits

...

2 Commits

Author SHA1 Message Date
Kukks
a774c09f79 make port binding respect defaults to avoid any behavior change from older versions 2022-08-17 08:39:22 +02:00
Kukks
42f6bead56 Allow bind and port for http too 2022-08-17 08:39:22 +02:00
2 changed files with 39 additions and 26 deletions

View File

@@ -167,40 +167,53 @@ namespace BTCPayServer.Hosting
bool hasCertPath = !String.IsNullOrEmpty(httpsCertificateFilePath); bool hasCertPath = !String.IsNullOrEmpty(httpsCertificateFilePath);
services.Configure<KestrelServerOptions>(kestrel => services.Configure<KestrelServerOptions>(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<IPAddress>("bind", IPAddress.Any);
int bindPort = Configuration.GetOrDefault<int>("port", 443);
services.Configure<KestrelServerOptions>(kestrel => var bindAddress = Configuration.GetOrDefault<IPAddress>("bind", null);
int? bindPort = Configuration.GetOrDefault("port", -1);
bindPort = bindPort == -1 ? null : bindPort;
if (hasCertPath || useDefaultCertificate)
{ {
bindAddress ??= IPAddress.Any;
bindPort ??= 443;
if (hasCertPath && !File.Exists(httpsCertificateFilePath)) if (hasCertPath && !File.Exists(httpsCertificateFilePath))
{ {
// Note that by design this is a fatal error condition that will cause the process to exit. // 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");
} }
kestrel.Listen(bindAddress, bindPort, l => if (hasCertPath && useDefaultCertificate)
{ {
if (hasCertPath) 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 =>
{
if (hasCertPath || useDefaultCertificate)
{ {
Logs.Configuration.LogInformation($"Using HTTPS with the certificate located in {httpsCertificateFilePath}."); if (hasCertPath)
l.UseHttps(httpsCertificateFilePath, Configuration.GetOrDefault<string>("HttpsCertificateFilePassword", null)); {
} Logs.Configuration.LogInformation(
else $"Using HTTPS with the certificate located in {httpsCertificateFilePath}.");
{ l.UseHttps(httpsCertificateFilePath,
Logs.Configuration.LogInformation($"Using HTTPS with the default certificate"); Configuration.GetOrDefault<string>("HttpsCertificateFilePassword", null));
l.UseHttps(); }
else
{
Logs.Configuration.LogInformation($"Using HTTPS with the default certificate");
l.UseHttps();
}
} }
}); });
}); }
} });
} }
public void Configure( public void Configure(
IApplicationBuilder app, IApplicationBuilder app,

View File

@@ -32,7 +32,7 @@
"BTCPAY_CHEATMODE": "true", "BTCPAY_CHEATMODE": "true",
"BTCPAY_EXPLORERPOSTGRES": "User ID=postgres;Include Error Detail=true;Host=127.0.0.1;Port=39372;Database=nbxplorer" "BTCPAY_EXPLORERPOSTGRES": "User ID=postgres;Include Error Detail=true;Host=127.0.0.1;Port=39372;Database=nbxplorer"
}, },
"applicationUrl": "http://0.0.0.0:14142/" "applicationUrl": "http://localhost:14142/"
}, },
"Bitcoin-HTTPS": { "Bitcoin-HTTPS": {
"commandName": "Project", "commandName": "Project",
@@ -70,7 +70,7 @@
"BTCPAY_CHEATMODE": "true", "BTCPAY_CHEATMODE": "true",
"BTCPAY_EXPLORERPOSTGRES": "User ID=postgres;Include Error Detail=true;Host=127.0.0.1;Port=39372;Database=nbxplorer" "BTCPAY_EXPLORERPOSTGRES": "User ID=postgres;Include Error Detail=true;Host=127.0.0.1;Port=39372;Database=nbxplorer"
}, },
"applicationUrl": "https://0.0.0.0:14142/" "applicationUrl": "https://localhost:14142/"
}, },
"Altcoins-HTTPS": { "Altcoins-HTTPS": {
"commandName": "Project", "commandName": "Project",
@@ -110,7 +110,7 @@
"BTCPAY_CHEATMODE": "true", "BTCPAY_CHEATMODE": "true",
"BTCPAY_EXPLORERPOSTGRES": "User ID=postgres;Include Error Detail=true;Host=127.0.0.1;Port=39372;Database=nbxplorer" "BTCPAY_EXPLORERPOSTGRES": "User ID=postgres;Include Error Detail=true;Host=127.0.0.1;Port=39372;Database=nbxplorer"
}, },
"applicationUrl": "https://0.0.0.0:14142/" "applicationUrl": "https://localhost:14142/"
} }
} }
} }