mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-23 06:35:13 +01:00
Can configure externalurl in case BTCPay is behind a reverse proxy
This commit is contained in:
parent
cff391a7a9
commit
e1f8177834
3 changed files with 22 additions and 3 deletions
|
@ -57,6 +57,7 @@ namespace BTCPayServer.Configuration
|
||||||
CookieFile = conf.GetOrDefault<string>("explorer.cookiefile", networkInfo.DefaultExplorerCookieFile);
|
CookieFile = conf.GetOrDefault<string>("explorer.cookiefile", networkInfo.DefaultExplorerCookieFile);
|
||||||
RequireHttps = conf.GetOrDefault<bool>("requirehttps", false);
|
RequireHttps = conf.GetOrDefault<bool>("requirehttps", false);
|
||||||
PostgresConnectionString = conf.GetOrDefault<string>("postgres", null);
|
PostgresConnectionString = conf.GetOrDefault<string>("postgres", null);
|
||||||
|
ExternalUrl = conf.GetOrDefault<Uri>("externalurl", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool RequireHttps
|
public bool RequireHttps
|
||||||
|
@ -68,5 +69,10 @@ namespace BTCPayServer.Configuration
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
public Uri ExternalUrl
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,8 @@ namespace BTCPayServer.Configuration
|
||||||
{
|
{
|
||||||
CommandLineApplication app = new CommandLineApplication(true)
|
CommandLineApplication app = new CommandLineApplication(true)
|
||||||
{
|
{
|
||||||
FullName = "NBXplorer\r\nLightweight block explorer for tracking HD wallets",
|
FullName = "BTCPay\r\nOpen source, self-hosted payment processor.",
|
||||||
Name = "NBXplorer"
|
Name = "BTCPay"
|
||||||
};
|
};
|
||||||
app.HelpOption("-? | -h | --help");
|
app.HelpOption("-? | -h | --help");
|
||||||
app.Option("-n | --network", $"Set the network among ({NetworkInformation.ToStringAll()}) (default: {Network.Main.ToString()})", CommandOptionType.SingleValue);
|
app.Option("-n | --network", $"Set the network among ({NetworkInformation.ToStringAll()}) (default: {Network.Main.ToString()})", CommandOptionType.SingleValue);
|
||||||
|
@ -30,7 +30,7 @@ namespace BTCPayServer.Configuration
|
||||||
app.Option("--postgres", $"Connection string to postgres database (default: sqlite is used)", CommandOptionType.SingleValue);
|
app.Option("--postgres", $"Connection string to postgres database (default: sqlite is used)", CommandOptionType.SingleValue);
|
||||||
app.Option("--explorerurl", $"Url of the NBxplorer (default: : Default setting of NBXplorer for the network)", CommandOptionType.SingleValue);
|
app.Option("--explorerurl", $"Url of the NBxplorer (default: : Default setting of NBXplorer for the network)", CommandOptionType.SingleValue);
|
||||||
app.Option("--explorercookiefile", $"Path to the cookie file (default: Default setting of NBXplorer for the network)", CommandOptionType.SingleValue);
|
app.Option("--explorercookiefile", $"Path to the cookie file (default: Default setting of NBXplorer for the network)", CommandOptionType.SingleValue);
|
||||||
|
app.Option("--externalurl", $"The expected external url of this service, use if BTCPay is behind a reverse proxy (default: empty, use the incoming HTTP request to figure out)", CommandOptionType.SingleValue);
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,13 +30,16 @@ namespace BTCPayServer.Hosting
|
||||||
TokenRepository _TokenRepository;
|
TokenRepository _TokenRepository;
|
||||||
RequestDelegate _Next;
|
RequestDelegate _Next;
|
||||||
CallbackController _CallbackController;
|
CallbackController _CallbackController;
|
||||||
|
BTCPayServerOptions _Options;
|
||||||
public BTCPayMiddleware(RequestDelegate next,
|
public BTCPayMiddleware(RequestDelegate next,
|
||||||
TokenRepository tokenRepo,
|
TokenRepository tokenRepo,
|
||||||
|
BTCPayServerOptions options,
|
||||||
CallbackController callbackController)
|
CallbackController callbackController)
|
||||||
{
|
{
|
||||||
_TokenRepository = tokenRepo ?? throw new ArgumentNullException(nameof(tokenRepo));
|
_TokenRepository = tokenRepo ?? throw new ArgumentNullException(nameof(tokenRepo));
|
||||||
_Next = next ?? throw new ArgumentNullException(nameof(next));
|
_Next = next ?? throw new ArgumentNullException(nameof(next));
|
||||||
_CallbackController = callbackController;
|
_CallbackController = callbackController;
|
||||||
|
_Options = options ?? throw new ArgumentNullException(nameof(options));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,6 +53,16 @@ namespace BTCPayServer.Hosting
|
||||||
_Registered = true;
|
_Registered = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make sure that code executing after this point think that the external url has been hit.
|
||||||
|
if(_Options.ExternalUrl != null)
|
||||||
|
{
|
||||||
|
httpContext.Request.Scheme = _Options.ExternalUrl.Scheme;
|
||||||
|
if(_Options.ExternalUrl.IsDefaultPort)
|
||||||
|
httpContext.Request.Host = new HostString(_Options.ExternalUrl.Host);
|
||||||
|
else
|
||||||
|
httpContext.Request.Host = new HostString(_Options.ExternalUrl.Host, _Options.ExternalUrl.Port);
|
||||||
|
}
|
||||||
|
|
||||||
httpContext.Request.Headers.TryGetValue("x-signature", out StringValues values);
|
httpContext.Request.Headers.TryGetValue("x-signature", out StringValues values);
|
||||||
var sig = values.FirstOrDefault();
|
var sig = values.FirstOrDefault();
|
||||||
httpContext.Request.Headers.TryGetValue("x-identity", out values);
|
httpContext.Request.Headers.TryGetValue("x-identity", out values);
|
||||||
|
|
Loading…
Add table
Reference in a new issue