Skip to content

How to match a file name and non-file name in appsettings.json? #1946

Answered by zwcloud
zwcloud asked this question in Q&A
Discussion options

You must be logged in to vote

Done. Followed the example in https://github.com/microsoft/reverse-proxy/blob/main/docs/docfx/articles/ab-testing.md

here is the solution:

IProxyStateLookup lookup = app.Services.GetRequiredService<IProxyStateLookup>();
var apiRegex = new Regex(@"^[a-zA-Z0-9/]+$");
string ChooseCluster(HttpContext context)
{
    var path = context.Request.Path.Value;
    var isIndex = path is null or "" or "/";
    var isApi = !isIndex && apiRegex.IsMatch(path);
    // Decide which cluster to use. This could be random, weighted, based on headers, etc.
    return isApi ? "api_cluster" : "file_cluster";
}

app.MapReverseProxy(proxyPipeline => {
    // Custom cluster selection
    proxyPipeline.Use(async (co…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Tratcher
Comment options

Tratcher Dec 1, 2022
Collaborator

Answer selected by Tratcher
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants