From a4c2ae3e280d6813b2f32f3024432230bc7d29e6 Mon Sep 17 00:00:00 2001 From: Timerix Date: Sun, 23 Mar 2025 02:44:51 +0500 Subject: [PATCH] HomeRoute removed (use MapRoute "/") --- DTLib.Web/DTLib.Web.csproj | 2 +- DTLib.Web/Routes/SimpleRouter.cs | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/DTLib.Web/DTLib.Web.csproj b/DTLib.Web/DTLib.Web.csproj index fd9145c..96e419b 100644 --- a/DTLib.Web/DTLib.Web.csproj +++ b/DTLib.Web/DTLib.Web.csproj @@ -2,7 +2,7 @@ DTLib.Web - 1.2.0 + 1.2.1 Timerix HTTP Server with simple routing GIT diff --git a/DTLib.Web/Routes/SimpleRouter.cs b/DTLib.Web/Routes/SimpleRouter.cs index 8d808e4..972dbe7 100644 --- a/DTLib.Web/Routes/SimpleRouter.cs +++ b/DTLib.Web/Routes/SimpleRouter.cs @@ -2,12 +2,9 @@ namespace DTLib.Web.Routes; public class SimpleRouter : IRouter { - /// route for base url - public RouteHandler? HomePageRoute { get; set; } /// route for any url that doesn't have its own handler public RouteHandler? DefaultRoute { get; set; } - private readonly Dictionary _routes = new(); private readonly ILogger _logger; @@ -23,11 +20,11 @@ public class SimpleRouter : IRouter public async Task Resolve(HttpListenerContext ctx) { - string requestPath = ctx.Request.Url?.AbsolutePath ?? "/"; - RouteHandler? route; - if(HomePageRoute != null && requestPath == "/") - route = HomePageRoute; - else if (!_routes.TryGetValue($"{requestPath}:{ctx.Request.HttpMethod}", out route)) + + string? requestPath = ctx.Request.Url?.AbsolutePath; + if (string.IsNullOrEmpty(requestPath)) + requestPath = "/"; + if (!_routes.TryGetValue($"{requestPath}:{ctx.Request.HttpMethod}", out var route)) route = DefaultRoute; HttpStatusCode status;