From e34b1b54d566e868b6d6cacbce3bf1532f7bd81c Mon Sep 17 00:00:00 2001 From: sbwalker Date: Tue, 12 Dec 2023 14:50:08 -0500 Subject: [PATCH] add support for root sitemap.xml and robots.txt --- .../Middleware/TenantMiddleware.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Oqtane.Server/Infrastructure/Middleware/TenantMiddleware.cs b/Oqtane.Server/Infrastructure/Middleware/TenantMiddleware.cs index 0c415f85..f6d7649c 100644 --- a/Oqtane.Server/Infrastructure/Middleware/TenantMiddleware.cs +++ b/Oqtane.Server/Infrastructure/Middleware/TenantMiddleware.cs @@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Caching.Memory; using Oqtane.Repository; using Oqtane.Shared; +using SixLabors.ImageSharp.Metadata.Profiles.Exif; namespace Oqtane.Infrastructure { @@ -60,6 +61,22 @@ namespace Oqtane.Infrastructure context.Request.Path = path.Replace("/" + alias.Path, ""); } } + + // handle sitemap.xml root request (does not support subfolder aliases) + if (context.Request.Path.StartsWithSegments("/sitemap.xml")) + { + context.Request.Path = "/pages" + context.Request.Path; + } + + // handle robots.txt root request (does not support subfolder aliases) + if (context.Request.Path.StartsWithSegments("/robots.txt")) + { + // allow all and specify site map + var robots = $"User-agent: *\n\nSitemap: {context.Request.Scheme}://{alias.Name}/pages/sitemap.xml"; + context.Response.ContentType = "text/plain"; + await context.Response.WriteAsync(robots); + return; + } } }