Skip to content

Commit

Permalink
Better path resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonAquitaine committed Nov 12, 2023
1 parent 1bdf28d commit 2a0f11b
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions Zen.Web/Middleware/Html5Router.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
{
Expand All @@ -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;
Expand Down

0 comments on commit 2a0f11b

Please sign in to comment.