From 64e025d9f7da72121e1941b0987858c2c5d2f565 Mon Sep 17 00:00:00 2001 From: Mohammad Mahdi Date: Wed, 20 Aug 2025 13:44:01 +0330 Subject: [PATCH] Update route handling to modify existing routes instead of duplicating --- VirtualDDNSRouter.Server/Program.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/VirtualDDNSRouter.Server/Program.cs b/VirtualDDNSRouter.Server/Program.cs index 4624e1e..8f3b1d9 100644 --- a/VirtualDDNSRouter.Server/Program.cs +++ b/VirtualDDNSRouter.Server/Program.cs @@ -42,12 +42,21 @@ app.MapGet("/setip/{path}/{port}/{apiKey}", async (IYamlParser yamlParser ,HttpC app.Logger.LogInformation($"Could not get the client ip address for {path} with port {port}."); return Results.BadRequest("Could not get the client ip address"); } - routes.Add(new Route + var existingRoute = routes.FirstOrDefault(r => r.path == path); + if (existingRoute is not null) { - ipAddress = clientIp, - path = path, - port = port - }); + existingRoute.ipAddress = clientIp; + existingRoute.port = port; + } + else + { + routes.Add(new Route + { + ipAddress = clientIp, + path = path, + port = port + }); + } return Results.Ok($"goto/{path}"); });