From 2a0f11bd129da8b4226b52fc56092cb057e5d3d8 Mon Sep 17 00:00:00 2001 From: Leon Aquitaine Date: Sat, 11 Nov 2023 23:27:24 -0500 Subject: [PATCH] Better path resolution --- Zen.Web/Middleware/Html5Router.cs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Zen.Web/Middleware/Html5Router.cs b/Zen.Web/Middleware/Html5Router.cs index 2e89a3f..dfa5508 100644 --- a/Zen.Web/Middleware/Html5Router.cs +++ b/Zen.Web/Middleware/Html5Router.cs @@ -56,20 +56,20 @@ public static void UseHtml5Routing(this IApplicationBuilder app) app.Use(async (context, next) => { var path = context.Request.Path.ToString().ToLower(); - if (path.StartsWith("/")) path = path[1..]; - var physicalPath = Path.Combine("wwwroot", path); + if (path.StartsWith("/api") || path.EndsWith(".map")) { await next.Invoke(); return; } + + var pathParts = path.Split('/', StringSplitOptions.RemoveEmptyEntries).ToList(); + pathParts.Insert(0, "wwwroot"); + + var physicalPath = Path.Combine(pathParts.ToArray()); + + Zen.Base.Log.Add(context.Request.Path + context.Request.QueryString, Base.Module.Log.Message.EContentType.Debug); + Zen.Base.Log.Add(physicalPath, Base.Module.Log.Message.EContentType.Debug); await LogRequest(context); - if (File.Exists(physicalPath) || - path.StartsWith("/api") || - path.EndsWith(".map") - ) - { - await next.Invoke(); - return; - } + if (File.Exists(physicalPath)) { await next.Invoke(); return; } if (context.Request.Headers.ContainsKey("user-agent")) { @@ -78,7 +78,7 @@ public static void UseHtml5Routing(this IApplicationBuilder app) if (sig != null) { var result = cardRender.GetCardDetails(context.Request).Render(context.Request); - Base.Log.KeyValuePair("Card Generator", sig + "::" + path); + Base.Log.KeyValuePair("Card Generator", $"{sig}::{path}"); context.Response.ContentType = "text/html; charset=utf-8"; await context.Response.WriteAsync(result); return;