diff --git a/BTCPayServer/BTCPayServer.csproj b/BTCPayServer/BTCPayServer.csproj index 0602925c6..7aa659748 100644 --- a/BTCPayServer/BTCPayServer.csproj +++ b/BTCPayServer/BTCPayServer.csproj @@ -55,7 +55,6 @@ - diff --git a/BTCPayServer/Controllers/HomeController.cs b/BTCPayServer/Controllers/HomeController.cs index 6747570ff..5c46284e0 100644 --- a/BTCPayServer/Controllers/HomeController.cs +++ b/BTCPayServer/Controllers/HomeController.cs @@ -8,6 +8,8 @@ using BTCPayServer.Models; using NBitcoin.DataEncoders; using NBitcoin.Payment; using System.Net.Http; +using System.Text; +using BTCPayServer.Services; using Newtonsoft.Json.Linq; using NBitcoin; using Newtonsoft.Json; @@ -16,10 +18,12 @@ namespace BTCPayServer.Controllers { public class HomeController : Controller { + private readonly SettingsRepository _SettingsRepository; public IHttpClientFactory HttpClientFactory { get; } - public HomeController(IHttpClientFactory httpClientFactory) + public HomeController(IHttpClientFactory httpClientFactory, SettingsRepository settingsRepository) { + _SettingsRepository = settingsRepository; HttpClientFactory = httpClientFactory; } public IActionResult Index() @@ -103,5 +107,16 @@ namespace BTCPayServer.Controllers { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } + [Route("robots.txt")] + public async Task Robots() + { + var settings = await _SettingsRepository.GetSettingAsync(); + StringBuilder stringBuilder = new StringBuilder(); + + stringBuilder.AppendLine("user-agent: *"); + stringBuilder.AppendLine($"disallow: {(settings.DiscourageSearchEngines? "/": string.Empty)}"); + + return Content(stringBuilder.ToString(), "text/plain", Encoding.UTF8); + } } } diff --git a/BTCPayServer/Hosting/BTCPayRobotProvider.cs b/BTCPayServer/Hosting/BTCPayRobotProvider.cs deleted file mode 100644 index f3c12eff2..000000000 --- a/BTCPayServer/Hosting/BTCPayRobotProvider.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Collections.Generic; -using BTCPayServer.Services; -using Robotify.AspNetCore; - -namespace BTCPayServer.Hosting -{ - public class BTCPayRobotProvider : IRobotifyRobotGroupProvider - { - private readonly SettingsRepository _SettingsRepository; - - public BTCPayRobotProvider(SettingsRepository settingsRepository) - { - _SettingsRepository = settingsRepository; - } - public IEnumerable Get() - { - var settings = _SettingsRepository.GetSettingAsync().GetAwaiter().GetResult(); - if (settings.DiscourageSearchEngines) - { - yield return new RobotGroup() - { - UserAgent = "*", - Disallow = new[] {"/"} - }; - } - else - { - yield return new RobotGroup() - { - UserAgent = "*", - Disallow = Array.Empty() - }; - } - - } - } -} \ No newline at end of file diff --git a/BTCPayServer/Hosting/Startup.cs b/BTCPayServer/Hosting/Startup.cs index cdecaad68..23e04db8e 100644 --- a/BTCPayServer/Hosting/Startup.cs +++ b/BTCPayServer/Hosting/Startup.cs @@ -61,7 +61,6 @@ namespace BTCPayServer.Hosting Logs.Configure(LoggerFactory); services.ConfigureBTCPayServer(Configuration); services.AddMemoryCache(); - services.AddRobotify(configurer => configurer.AddRobotGroupProvider()); services.AddIdentity() .AddEntityFrameworkStores() .AddDefaultTokenProviders(); @@ -179,7 +178,6 @@ namespace BTCPayServer.Hosting }); app.UseWebSockets(); app.UseStatusCodePages(); - app.UseRobotify(); app.UseMvc(routes => { routes.MapRoute(