From 84366812f9ab3c6013f8a3b3efaff0747a1eb87d Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Thu, 10 Jul 2025 18:32:58 +0100 Subject: [PATCH] Serve /robots.txt --- src/Yavsc/Extensions/HostingExtensions.cs | 12 +++++++++++- src/Yavsc/wwwroot/robots.txt | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Yavsc/Extensions/HostingExtensions.cs b/src/Yavsc/Extensions/HostingExtensions.cs index 7b91dbc3..ae15c313 100644 --- a/src/Yavsc/Extensions/HostingExtensions.cs +++ b/src/Yavsc/Extensions/HostingExtensions.cs @@ -314,7 +314,17 @@ public static class HostingExtensions await db.Database.MigrateAsync(); } } - + app.Use(async (context, next) => { + if (context.Request.Path.StartsWithSegments("/robots.txt")) { + var robotsTxtPath = System.IO.Path.Combine(app.Environment.WebRootPath, $"robots.txt"); + string output = "User-agent: * \nDisallow: /"; + if (File.Exists(robotsTxtPath)) { + output = await File.ReadAllTextAsync(robotsTxtPath); + } + context.Response.ContentType = "text/plain"; + await context.Response.WriteAsync(output); + } else await next(); + }); app.UseStaticFiles(); app.UseRouting(); app.UseIdentityServer(); diff --git a/src/Yavsc/wwwroot/robots.txt b/src/Yavsc/wwwroot/robots.txt index d621ad6e..36b14f74 100644 --- a/src/Yavsc/wwwroot/robots.txt +++ b/src/Yavsc/wwwroot/robots.txt @@ -1,5 +1,6 @@ User-agent: * Disallow: /signin +Disallow: /signin-google Disallow: /Account/Register +Disallow: /External Disallow: /Command/Create -