diff --git a/BTCPayServer/Configuration/BTCPayServerOptions.cs b/BTCPayServer/Configuration/BTCPayServerOptions.cs index da0954bd0..25f5b55b1 100644 --- a/BTCPayServer/Configuration/BTCPayServerOptions.cs +++ b/BTCPayServer/Configuration/BTCPayServerOptions.cs @@ -92,11 +92,14 @@ namespace BTCPayServer.Configuration PostgresConnectionString = conf.GetOrDefault("postgres", null); BundleJsCss = conf.GetOrDefault("bundlejscss", true); ExternalUrl = conf.GetOrDefault("externalurl", null); + + RootPath = conf.GetOrDefault("rootpath", "/"); + var old = conf.GetOrDefault("internallightningnode", null); if(old != null) throw new ConfigException($"internallightningnode should not be used anymore, use btclightning instead"); } - + public string RootPath { get; set; } public Dictionary InternalLightningByCryptoCode { get; set; } = new Dictionary(); public BTCPayNetworkProvider NetworkProvider { get; set; } diff --git a/BTCPayServer/Configuration/DefaultConfiguration.cs b/BTCPayServer/Configuration/DefaultConfiguration.cs index 769bce1f6..a25fb5bbd 100644 --- a/BTCPayServer/Configuration/DefaultConfiguration.cs +++ b/BTCPayServer/Configuration/DefaultConfiguration.cs @@ -31,6 +31,9 @@ namespace BTCPayServer.Configuration app.Option("--regtest | -regtest", $"Use regtest (Deprecated, use --network instead)", CommandOptionType.BoolValue); app.Option("--chains | -c", $"Chains to support comma separated (default: btc, available: {chains})", CommandOptionType.SingleValue); app.Option("--postgres", $"Connection string to postgres database (default: sqlite is used)", CommandOptionType.SingleValue); + app.Option("--externalurl", $"The expected external url of this service, to use if BTCPay is behind a reverse proxy (default: empty, use the incoming HTTP request to figure out)", CommandOptionType.SingleValue); + app.Option("--bundlejscss", $"Bundle javascript and css files for better performance (default: true)", CommandOptionType.SingleValue); + app.Option("--rootpath", "The root path in the URL to access BTCPay (default: /)", CommandOptionType.SingleValue); foreach (var network in provider.GetAll()) { var crypto = network.CryptoCode.ToLowerInvariant(); @@ -38,8 +41,6 @@ namespace BTCPayServer.Configuration app.Option($"--{crypto}explorercookiefile", $"Path to the cookie file (default: {network.NBXplorerNetwork.DefaultSettings.DefaultCookieFile})", CommandOptionType.SingleValue); app.Option($"--{crypto}lightning", $"Easy configuration of lightning for the server adnistrator: Must be a unix socket of CLightning (lightning-rpc) or URL to a charge server (default: empty)", CommandOptionType.SingleValue); } - app.Option("--externalurl", $"The expected external url of this service, to use if BTCPay is behind a reverse proxy (default: empty, use the incoming HTTP request to figure out)", CommandOptionType.SingleValue); - app.Option("--bundlejscss", $"Bundle javascript and css files for better performance (default: true)", CommandOptionType.SingleValue); return app; } diff --git a/BTCPayServer/Hosting/Startup.cs b/BTCPayServer/Hosting/Startup.cs index afa361675..fe3792f5b 100644 --- a/BTCPayServer/Hosting/Startup.cs +++ b/BTCPayServer/Hosting/Startup.cs @@ -147,7 +147,25 @@ namespace BTCPayServer.Hosting IApplicationBuilder app, IHostingEnvironment env, IServiceProvider prov, + BTCPayServerOptions options, ILoggerFactory loggerFactory) + { + Logs.Configure(loggerFactory); + Logs.Configuration.LogInformation($"Root Path: {options.RootPath}"); + if (options.RootPath.Equals("/", StringComparison.OrdinalIgnoreCase)) + { + ConfigureCore(app, env, prov, loggerFactory); + } + else + { + app.Map(options.RootPath, appChild => + { + ConfigureCore(appChild, env, prov, loggerFactory); + }); + } + } + + private static void ConfigureCore(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider prov, ILoggerFactory loggerFactory) { if (env.IsDevelopment()) { @@ -155,9 +173,6 @@ namespace BTCPayServer.Hosting app.UseBrowserLink(); } - - Logs.Configure(loggerFactory); - //App insight do not that by itself... loggerFactory.AddApplicationInsights(prov, LogLevel.Information);