diff --git a/src/BlazorUI/Demo/Bit.BlazorUI.Demo.Server/Startup/Middlewares.cs b/src/BlazorUI/Demo/Bit.BlazorUI.Demo.Server/Startup/Middlewares.cs index b3086ec902..9dc47f34e7 100644 --- a/src/BlazorUI/Demo/Bit.BlazorUI.Demo.Server/Startup/Middlewares.cs +++ b/src/BlazorUI/Demo/Bit.BlazorUI.Demo.Server/Startup/Middlewares.cs @@ -3,6 +3,7 @@ using System.Runtime.Loader; using Bit.BlazorUI.Demo.Server.Components; using HealthChecks.UI.Client; +using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Endpoints; using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.AspNetCore.Http.Extensions; @@ -81,6 +82,8 @@ public static void Use(WebApplication app, IWebHostEnvironment env, IConfigurati }); } + UseSiteMap(app); + // Handle the rest of requests with blazor app.MapStaticAssets(); app.MapRazorComponents() @@ -141,4 +144,32 @@ private static void Configure_401_403_404_Pages(WebApplication app) } }); } + + private static void UseSiteMap(WebApplication app) + { + var urls = Assembly.Load("Bit.BlazorUI.Demo.Client.Core") + .ExportedTypes + .Where(t => typeof(IComponent).IsAssignableFrom(t)) + .SelectMany(t => t.GetCustomAttributes()) + .Select(r => r.Template) + .ToList(); + + const string siteMapHeader = "\r\n"; + + app.MapGet("/sitemap.xml", async context => + { + if (siteMap is null) + { + var baseUrl = context.Request.GetBaseUrl(); + + siteMap = $"{siteMapHeader}{string.Join(Environment.NewLine, urls.Select(u => $"{new Uri(baseUrl, u)}"))}"; + } + + context.Response.Headers.ContentType = "application/xml"; + + await context.Response.WriteAsync(siteMap, context.RequestAborted); + }); + } + + private static string? siteMap; } diff --git a/src/Websites/Careers/src/Bit.Websites.Careers.Server/Startup/Middlewares.cs b/src/Websites/Careers/src/Bit.Websites.Careers.Server/Startup/Middlewares.cs index c19941e03a..b8d762807b 100644 --- a/src/Websites/Careers/src/Bit.Websites.Careers.Server/Startup/Middlewares.cs +++ b/src/Websites/Careers/src/Bit.Websites.Careers.Server/Startup/Middlewares.cs @@ -3,10 +3,9 @@ using System.Runtime.Loader; using Bit.Websites.Careers.Server.Components; using HealthChecks.UI.Client; -using Microsoft.AspNetCore.Components.Endpoints; +using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.AspNetCore.Http.Extensions; -using Microsoft.Net.Http.Headers; namespace Bit.Websites.Careers.Server.Startup; @@ -73,6 +72,8 @@ public static void Use(WebApplication app, IWebHostEnvironment env, IConfigurati app.MapHealthChecksUI(); } + UseSiteMap(app); + app.MapStaticAssets(); app.MapRazorComponents() .AddInteractiveServerRenderMode() @@ -113,4 +114,32 @@ private static void Configure_404_Page(WebApplication app) } }); } + + private static void UseSiteMap(WebApplication app) + { + var urls = Assembly.Load("Bit.Websites.Careers.Client") + .ExportedTypes + .Where(t => typeof(IComponent).IsAssignableFrom(t)) + .SelectMany(t => t.GetCustomAttributes()) + .Select(r => r.Template) + .ToList(); + + const string siteMapHeader = "\r\n"; + + app.MapGet("/sitemap.xml", async context => + { + if (siteMap is null) + { + var baseUrl = new Uri(context.Request.GetBaseUrl()); + + siteMap = $"{siteMapHeader}{string.Join(Environment.NewLine, urls.Select(u => $"{new Uri(baseUrl, u)}"))}"; + } + + context.Response.Headers.ContentType = "application/xml"; + + await context.Response.WriteAsync(siteMap, context.RequestAborted); + }); + } + + private static string? siteMap; } diff --git a/src/Websites/Platform/src/Bit.Websites.Platform.Server/Startup/Middlewares.cs b/src/Websites/Platform/src/Bit.Websites.Platform.Server/Startup/Middlewares.cs index c064011c41..3fb3814349 100644 --- a/src/Websites/Platform/src/Bit.Websites.Platform.Server/Startup/Middlewares.cs +++ b/src/Websites/Platform/src/Bit.Websites.Platform.Server/Startup/Middlewares.cs @@ -3,6 +3,7 @@ using System.Runtime.Loader; using Bit.Websites.Platform.Server.Components; using HealthChecks.UI.Client; +using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.AspNetCore.Http.Extensions; @@ -71,6 +72,8 @@ public static void Use(WebApplication app, IWebHostEnvironment env, IConfigurati app.MapHealthChecksUI(); } + UseSiteMap(app); + app.MapStaticAssets(); app.MapRazorComponents() .AddInteractiveServerRenderMode() @@ -111,4 +114,32 @@ private static void Configure_404_Page(WebApplication app) } }); } + + private static void UseSiteMap(WebApplication app) + { + var urls = Assembly.Load("Bit.Websites.Platform.Client") + .ExportedTypes + .Where(t => typeof(IComponent).IsAssignableFrom(t)) + .SelectMany(t => t.GetCustomAttributes()) + .Select(r => r.Template) + .ToList(); + + const string siteMapHeader = "\r\n"; + + app.MapGet("/sitemap.xml", async context => + { + if (siteMap is null) + { + var baseUrl = new Uri(context.Request.GetBaseUrl()); + + siteMap = $"{siteMapHeader}{string.Join(Environment.NewLine, urls.Select(u => $"{new Uri(baseUrl, u)}"))}"; + } + + context.Response.Headers.ContentType = "application/xml"; + + await context.Response.WriteAsync(siteMap, context.RequestAborted); + }); + } + + private static string? siteMap; } diff --git a/src/Websites/Sales/src/Bit.Websites.Sales.Server/Startup/Middlewares.cs b/src/Websites/Sales/src/Bit.Websites.Sales.Server/Startup/Middlewares.cs index fe5c9b83f5..923ecdb312 100644 --- a/src/Websites/Sales/src/Bit.Websites.Sales.Server/Startup/Middlewares.cs +++ b/src/Websites/Sales/src/Bit.Websites.Sales.Server/Startup/Middlewares.cs @@ -2,11 +2,10 @@ using HealthChecks.UI.Client; using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.AspNetCore.Http.Extensions; -using Microsoft.Net.Http.Headers; using Bit.Websites.Sales.Server.Components; using System.Net; -using Microsoft.AspNetCore.Components.Endpoints; using System.Runtime.Loader; +using Microsoft.AspNetCore.Components; namespace Bit.Websites.Sales.Server.Startup; @@ -73,6 +72,8 @@ public static void Use(WebApplication app, IWebHostEnvironment env, IConfigurati app.MapHealthChecksUI(); } + UseSiteMap(app); + app.MapStaticAssets(); app.MapRazorComponents() .AddInteractiveServerRenderMode() @@ -113,4 +114,32 @@ private static void Configure_404_Page(WebApplication app) } }); } + + private static void UseSiteMap(WebApplication app) + { + var urls = Assembly.Load("Bit.Websites.Sales.Client") + .ExportedTypes + .Where(t => typeof(IComponent).IsAssignableFrom(t)) + .SelectMany(t => t.GetCustomAttributes()) + .Select(r => r.Template) + .ToList(); + + const string siteMapHeader = "\r\n"; + + app.MapGet("/sitemap.xml", async context => + { + if (siteMap is null) + { + var baseUrl = new Uri(context.Request.GetBaseUrl()); + + siteMap = $"{siteMapHeader}{string.Join(Environment.NewLine, urls.Select(u => $"{new Uri(baseUrl, u)}"))}"; + } + + context.Response.Headers.ContentType = "application/xml"; + + await context.Response.WriteAsync(siteMap, context.RequestAborted); + }); + } + + private static string? siteMap; }