Browse Source

Fix cors and prefix rewriting

davidfowl/common-services
David Fowler 1 year ago
committed by Reuben Bond
parent
commit
561d48bc62
3 changed files with 14 additions and 13 deletions
  1. +11
    -11
      src/ApiGateways/Web.Bff.Shopping/aggregator/Extensions/Extensions.cs
  2. +2
    -2
      src/ApiGateways/Web.Bff.Shopping/aggregator/Program.cs
  3. +1
    -0
      src/Web/WebMVC/appsettings.json

+ 11
- 11
src/ApiGateways/Web.Bff.Shopping/aggregator/Extensions/Extensions.cs View File

@ -6,25 +6,25 @@ internal static class Extensions
public static IServiceCollection AddReverseProxy(this IServiceCollection services, IConfiguration configuration)
{
// REVIEW: This should come from configuration
var s = new (string, string, string)[]
var s = new (string, string, string, bool)[]
{
("c-short", "c", "catalog"),
("c-long", "catalog-api", "catalog"),
("c-short", "c", "catalog", true),
("c-long", "catalog-api", "catalog", true),
("b-short", "b", "basket"),
("b-long", "basket-api", "basket"),
("b-short", "b", "basket", true),
("b-long", "basket-api", "basket", true),
("o-short", "o", "orders"),
("o-long", "ordering-api", "orders"),
("o-short", "o", "orders", true) ,
("o-long", "ordering-api", "orders", true),
("h-long", "hub/notificationhub", "signalr")
("h-long", "hub/notificationhub", "signalr", false)
};
var routes = new List<RouteConfig>();
var clusters = new Dictionary<string, ClusterConfig>();
var urls = configuration.GetRequiredSection("Urls");
foreach (var (routeId, prefix, clusterId) in s)
foreach (var (routeId, prefix, clusterId, rewritePrefix) in s)
{
var destination = urls.GetRequiredValue(clusterId);
@ -36,10 +36,10 @@ internal static class Extensions
{
Path = $"/{prefix}/{{**catch-all}}"
},
Metadata = new Dictionary<string, string>()
Metadata = rewritePrefix ? new Dictionary<string, string>()
{
["prefix"] = prefix
}
} : null
});
clusters[clusterId] = new()


+ 2
- 2
src/ApiGateways/Web.Bff.Shopping/aggregator/Program.cs View File

@ -27,13 +27,13 @@ app.UseServiceDefaults();
app.UseHttpsRedirection();
app.UseCors();
app.UseCors("CorsPolicy");
app.UseAuthentication();
app.UseAuthorization();
app.MapGet("/", () => Results.Redirect("/swagger"));
app.MapControllers().RequireCors("CorsPolicy");
app.MapControllers();
app.MapReverseProxy();
await app.RunAsync();

+ 1
- 0
src/Web/WebMVC/appsettings.json View File

@ -1,5 +1,6 @@
{
"PurchaseUrl": "http://localhost:5229",
"SignalrHubUrl": "http://localhost:5229",
"IdentityUrl": "http://localhost:5223",
"IdentityUrlHC": "http://localhost:5223/hc",
"CallBackUrl": "http://localhost:5100/",


Loading…
Cancel
Save