Fix router frontdoor readiness and route contracts
This commit is contained in:
@@ -40,6 +40,11 @@ public static class GatewayOptionsValidator
|
||||
_ = GatewayValueParser.ParseDuration(options.Health.DegradedThreshold, TimeSpan.FromSeconds(15));
|
||||
_ = GatewayValueParser.ParseDuration(options.Health.CheckInterval, TimeSpan.FromSeconds(5));
|
||||
|
||||
if (options.Health.RequiredMicroservices.Any(service => string.IsNullOrWhiteSpace(service)))
|
||||
{
|
||||
throw new InvalidOperationException("Gateway health required microservices must not contain empty values.");
|
||||
}
|
||||
|
||||
ValidateRoutes(options.Routes);
|
||||
}
|
||||
|
||||
@@ -133,6 +138,23 @@ public static class GatewayOptionsValidator
|
||||
{
|
||||
_ = GatewayValueParser.ParseDuration(route.DefaultTimeout, TimeSpan.FromSeconds(30));
|
||||
}
|
||||
|
||||
if (route.IsRegex && !string.IsNullOrWhiteSpace(route.TranslatesTo))
|
||||
{
|
||||
var regex = new Regex(route.Path);
|
||||
var groupCount = regex.GetGroupNumbers().Length;
|
||||
var refs = Regex.Matches(route.TranslatesTo, @"\$(\d+)");
|
||||
foreach (Match refMatch in refs)
|
||||
{
|
||||
var groupNum = int.Parse(refMatch.Groups[1].Value);
|
||||
if (groupNum >= groupCount)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"{prefix}: TranslatesTo references ${groupNum} but regex only has {groupCount - 1} capture groups.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user