Update route handling to modify existing routes instead of duplicating
This commit is contained in:
@@ -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}.");
|
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");
|
return Results.BadRequest("Could not get the client ip address");
|
||||||
}
|
}
|
||||||
|
var existingRoute = routes.FirstOrDefault(r => r.path == path);
|
||||||
|
if (existingRoute is not null)
|
||||||
|
{
|
||||||
|
existingRoute.ipAddress = clientIp;
|
||||||
|
existingRoute.port = port;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
routes.Add(new Route
|
routes.Add(new Route
|
||||||
{
|
{
|
||||||
ipAddress = clientIp,
|
ipAddress = clientIp,
|
||||||
path = path,
|
path = path,
|
||||||
port = port
|
port = port
|
||||||
});
|
});
|
||||||
|
}
|
||||||
return Results.Ok($"goto/{path}");
|
return Results.Ok($"goto/{path}");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user