♻️ Refactor Gateway and expose swagger
This commit is contained in:
@@ -9,11 +9,8 @@ public static class ApplicationBuilderExtensions
|
|||||||
public static WebApplication ConfigureAppMiddleware(this WebApplication app, ITusStore tusStore)
|
public static WebApplication ConfigureAppMiddleware(this WebApplication app, ITusStore tusStore)
|
||||||
{
|
{
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (app.Environment.IsDevelopment())
|
app.UseSwagger();
|
||||||
{
|
app.UseSwaggerUI();
|
||||||
app.UseSwagger();
|
|
||||||
app.UseSwaggerUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
|
@@ -32,132 +32,78 @@ builder.Services.AddRateLimiter(options =>
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var routes = new[]
|
var serviceNames = new[] { "ring", "pass", "drive", "sphere", "develop" };
|
||||||
|
|
||||||
|
var specialRoutes = new[]
|
||||||
{
|
{
|
||||||
new RouteConfig()
|
new RouteConfig
|
||||||
{
|
{
|
||||||
RouteId = "ring-ws",
|
RouteId = "ring-ws",
|
||||||
ClusterId = "ring",
|
ClusterId = "ring",
|
||||||
Match = new RouteMatch { Path = "/ws" }
|
Match = new RouteMatch { Path = "/ws" }
|
||||||
},
|
},
|
||||||
new RouteConfig()
|
new RouteConfig
|
||||||
{
|
|
||||||
RouteId = "ring-api",
|
|
||||||
ClusterId = "ring",
|
|
||||||
Match = new RouteMatch { Path = "/ring/{**catch-all}" },
|
|
||||||
Transforms =
|
|
||||||
[
|
|
||||||
new Dictionary<string, string> { { "PathRemovePrefix", "/ring" } },
|
|
||||||
new Dictionary<string, string> { { "PathPrefix", "/api" } }
|
|
||||||
]
|
|
||||||
},
|
|
||||||
new RouteConfig()
|
|
||||||
{
|
{
|
||||||
RouteId = "pass-openid",
|
RouteId = "pass-openid",
|
||||||
ClusterId = "pass",
|
ClusterId = "pass",
|
||||||
Match = new RouteMatch { Path = "/.well-known/openid-configuration" }
|
Match = new RouteMatch { Path = "/.well-known/openid-configuration" }
|
||||||
},
|
},
|
||||||
new RouteConfig()
|
new RouteConfig
|
||||||
{
|
{
|
||||||
RouteId = "pass-jwks",
|
RouteId = "pass-jwks",
|
||||||
ClusterId = "pass",
|
ClusterId = "pass",
|
||||||
Match = new RouteMatch { Path = "/.well-known/jwks" }
|
Match = new RouteMatch { Path = "/.well-known/jwks" }
|
||||||
},
|
},
|
||||||
new RouteConfig()
|
new RouteConfig
|
||||||
{
|
|
||||||
RouteId = "pass-api",
|
|
||||||
ClusterId = "pass",
|
|
||||||
Match = new RouteMatch { Path = "/id/{**catch-all}" },
|
|
||||||
Transforms =
|
|
||||||
[
|
|
||||||
new Dictionary<string, string> { { "PathRemovePrefix", "/id" } },
|
|
||||||
new Dictionary<string, string> { { "PathPrefix", "/api" } }
|
|
||||||
]
|
|
||||||
},
|
|
||||||
new RouteConfig()
|
|
||||||
{
|
{
|
||||||
RouteId = "drive-tus",
|
RouteId = "drive-tus",
|
||||||
ClusterId = "drive",
|
ClusterId = "drive",
|
||||||
Match = new RouteMatch { Path = "/api/tus" }
|
Match = new RouteMatch { Path = "/api/tus" }
|
||||||
},
|
|
||||||
new RouteConfig()
|
|
||||||
{
|
|
||||||
RouteId = "drive-api",
|
|
||||||
ClusterId = "drive",
|
|
||||||
Match = new RouteMatch { Path = "/drive/{**catch-all}" },
|
|
||||||
Transforms =
|
|
||||||
[
|
|
||||||
new Dictionary<string, string> { { "PathRemovePrefix", "/drive" } },
|
|
||||||
new Dictionary<string, string> { { "PathPrefix", "/api" } }
|
|
||||||
]
|
|
||||||
},
|
|
||||||
new RouteConfig()
|
|
||||||
{
|
|
||||||
RouteId = "sphere-api",
|
|
||||||
ClusterId = "sphere",
|
|
||||||
Match = new RouteMatch { Path = "/sphere/{**catch-all}" },
|
|
||||||
Transforms =
|
|
||||||
[
|
|
||||||
new Dictionary<string, string> { { "PathRemovePrefix", "/sphere" } },
|
|
||||||
new Dictionary<string, string> { { "PathPrefix", "/api" } }
|
|
||||||
]
|
|
||||||
},
|
|
||||||
new RouteConfig()
|
|
||||||
{
|
|
||||||
RouteId = "develop-api",
|
|
||||||
ClusterId = "develop",
|
|
||||||
Match = new RouteMatch { Path = "/develop/{**catch-all}" },
|
|
||||||
Transforms =
|
|
||||||
[
|
|
||||||
new Dictionary<string, string> { { "PathRemovePrefix", "/develop" } },
|
|
||||||
new Dictionary<string, string> { { "PathPrefix", "/api" } }
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var clusters = new[]
|
var apiRoutes = serviceNames.Select(serviceName =>
|
||||||
{
|
{
|
||||||
new ClusterConfig()
|
var apiPath = serviceName switch
|
||||||
{
|
{
|
||||||
ClusterId = "ring",
|
"pass" => "/id",
|
||||||
Destinations = new Dictionary<string, DestinationConfig>
|
_ => $"/{serviceName}"
|
||||||
{
|
};
|
||||||
{ "destination1", new DestinationConfig() { Address = "http://ring" } }
|
return new RouteConfig
|
||||||
}
|
|
||||||
},
|
|
||||||
new ClusterConfig()
|
|
||||||
{
|
{
|
||||||
ClusterId = "pass",
|
RouteId = $"{serviceName}-api",
|
||||||
Destinations = new Dictionary<string, DestinationConfig>
|
ClusterId = serviceName,
|
||||||
{
|
Match = new RouteMatch { Path = $"{apiPath}/{{**catch-all}}" },
|
||||||
{ "destination1", new DestinationConfig() { Address = "http://pass" } }
|
Transforms =
|
||||||
}
|
[
|
||||||
},
|
new Dictionary<string, string> { { "PathRemovePrefix", apiPath } },
|
||||||
new ClusterConfig()
|
new Dictionary<string, string> { { "PathPrefix", "/api" } }
|
||||||
|
]
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
var swaggerRoutes = serviceNames.Select(serviceName => new RouteConfig
|
||||||
|
{
|
||||||
|
RouteId = $"{serviceName}-swagger",
|
||||||
|
ClusterId = serviceName,
|
||||||
|
Match = new RouteMatch { Path = $"/swagger/{serviceName}/{{**catch-all}}" },
|
||||||
|
Transforms =
|
||||||
|
[
|
||||||
|
new Dictionary<string, string> { { "PathRemovePrefix", $"/swagger/{serviceName}" } },
|
||||||
|
new Dictionary<string, string> { { "PathPrefix", "/swagger" } }
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
var routes = specialRoutes.Concat(apiRoutes).Concat(swaggerRoutes).ToArray();
|
||||||
|
|
||||||
|
var clusters = serviceNames.Select(serviceName => new ClusterConfig
|
||||||
|
{
|
||||||
|
ClusterId = serviceName,
|
||||||
|
Destinations = new Dictionary<string, DestinationConfig>
|
||||||
{
|
{
|
||||||
ClusterId = "drive",
|
{ "destination1", new DestinationConfig { Address = $"http://{serviceName}" } }
|
||||||
Destinations = new Dictionary<string, DestinationConfig>
|
|
||||||
{
|
|
||||||
{ "destination1", new DestinationConfig() { Address = "http://drive" } }
|
|
||||||
}
|
|
||||||
},
|
|
||||||
new ClusterConfig()
|
|
||||||
{
|
|
||||||
ClusterId = "sphere",
|
|
||||||
Destinations = new Dictionary<string, DestinationConfig>
|
|
||||||
{
|
|
||||||
{ "destination1", new DestinationConfig() { Address = "http://sphere" } }
|
|
||||||
}
|
|
||||||
},
|
|
||||||
new ClusterConfig()
|
|
||||||
{
|
|
||||||
ClusterId = "develop",
|
|
||||||
Destinations = new Dictionary<string, DestinationConfig>
|
|
||||||
{
|
|
||||||
{ "destination1", new DestinationConfig() { Address = "http://develop" } }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
}).ToArray();
|
||||||
|
|
||||||
builder.Services
|
builder.Services
|
||||||
.AddReverseProxy()
|
.AddReverseProxy()
|
||||||
|
Reference in New Issue
Block a user