Browse Source

added yarp to public-web gateway

skoc10/publish-charts-artifacthub
Galip Tolga Erdem 5 years ago
parent
commit
0e73b9f16a
  1. 105
      gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbpWebPublicGatewayModule.cs
  2. 85
      gateways/web-public/src/EShopOnAbp.WebPublicGateway/appsettings.json

105
gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbpWebPublicGatewayModule.cs

@ -7,6 +7,7 @@ using Ocelot.Middleware;
using System.Collections.Generic;
using System.Linq;
using EShopOnAbp.Shared.Hosting.AspNetCore;
using Microsoft.AspNetCore.Http;
using Volo.Abp;
using Volo.Abp.Modularity;
using Microsoft.AspNetCore.Rewrite;
@ -23,21 +24,24 @@ public class EShopOnAbpWebPublicGatewayModule : AbpModule
var configuration = context.Services.GetConfiguration();
var hostingEnvironment = context.Services.GetHostingEnvironment();
SwaggerConfigurationHelper.ConfigureWithAuth(
context: context,
authority: configuration["AuthServer:Authority"],
scopes: new Dictionary<string, string> /* Requested scopes for authorization code request and descriptions for swagger UI only */
{
{ "AccountService", "Account Service API" },
{ "IdentityService", "Identity Service API" },
{ "AdministrationService", "Administration Service API" },
{ "CatalogService", "Catalog Service API" },
{ "BasketService", "Basket Service API" },
{ "PaymentService", "Payment Service API" },
{ "OrderingService", "Ordering Service API" },
},
apiTitle: "WebPublic Gateway"
);
// SwaggerConfigurationHelper.ConfigureWithAuth(
// context: context,
// authority: configuration["AuthServer:Authority"],
// scopes: new Dictionary<string, string> /* Requested scopes for authorization code request and descriptions for swagger UI only */
// {
// { "AccountService", "Account Service API" },
// { "IdentityService", "Identity Service API" },
// { "AdministrationService", "Administration Service API" },
// { "CatalogService", "Catalog Service API" },
// { "BasketService", "Basket Service API" },
// { "PaymentService", "Payment Service API" },
// { "OrderingService", "Ordering Service API" },
// },
// apiTitle: "WebPublic Gateway"
// );
context.Services.AddReverseProxy()
.LoadFromConfig(configuration.GetSection("ReverseProxy"));
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
@ -52,35 +56,50 @@ public class EShopOnAbpWebPublicGatewayModule : AbpModule
app.UseCorrelationId();
app.UseAbpSerilogEnrichers();
app.UseSwagger();
app.UseSwaggerUI(options =>
// app.UseSwagger();
// app.UseSwaggerUI(options =>
// {
// var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
// var routes = configuration.GetSection("Routes").Get<List<OcelotConfiguration>>();
// var routedServices = routes
// .GroupBy(t => t.ServiceKey)
// .Select(r => r.First())
// .Distinct();
//
// foreach (var config in routedServices)
// {
// var url =
// $"{config.DownstreamScheme}://{config.DownstreamHostAndPorts.FirstOrDefault()?.Host}:{config.DownstreamHostAndPorts.FirstOrDefault()?.Port}";
// if (!env.IsDevelopment())
// {
// url = $"https://{config.DownstreamHostAndPorts.FirstOrDefault()?.Host}";
// }
//
// options.SwaggerEndpoint($"{url}/swagger/v1/swagger.json", $"{config.ServiceKey} API");
// options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]);
// options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]);
// }
// });
//
// app.UseRewriter(new RewriteOptions()
// // Regex for "", "/" and "" (whitespace)
// .AddRedirect("^(|\\|\\s+)$", "/swagger"));
//
// app.UseOcelot().Wait();
// app.MapWhen(
// ctx => ctx.Request.Path.ToString().TrimEnd('/').Equals(""),
// app2 =>
// {
// app2.UseRouting();
// // app2.UseConfiguredEndpoints();
// app2.UseEndpoints(endpoints => endpoints.MapReverseProxy());
// }
// );
app.UseRouting();
app.UseEndpoints(endpoints =>
{
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
var routes = configuration.GetSection("Routes").Get<List<OcelotConfiguration>>();
var routedServices = routes
.GroupBy(t => t.ServiceKey)
.Select(r => r.First())
.Distinct();
foreach (var config in routedServices)
{
var url =
$"{config.DownstreamScheme}://{config.DownstreamHostAndPorts.FirstOrDefault()?.Host}:{config.DownstreamHostAndPorts.FirstOrDefault()?.Port}";
if (!env.IsDevelopment())
{
url = $"https://{config.DownstreamHostAndPorts.FirstOrDefault()?.Host}";
}
options.SwaggerEndpoint($"{url}/swagger/v1/swagger.json", $"{config.ServiceKey} API");
options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]);
options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]);
}
endpoints.MapGet("", ctx => ctx.Response.WriteAsync("YAG"));
endpoints.MapReverseProxy();
});
app.UseRewriter(new RewriteOptions()
// Regex for "", "/" and "" (whitespace)
.AddRedirect("^(|\\|\\s+)$", "/swagger"));
app.UseOcelot().Wait();
}
}

85
gateways/web-public/src/EShopOnAbp.WebPublicGateway/appsettings.json

@ -17,11 +17,94 @@
}
},
"AllowedHosts": "*",
"Redis": {
"Configuration": "localhost:6379"
},
"ElasticSearch": {
"Url": "http://localhost:9200"
},
"ReverseProxy": {
"Routes": {
"account-route": {
"ClusterId": "account-cluster",
"Match": {
"Path": "/api/account/{**everything}"
}
},
"administration-route": {
"ClusterId": "administration-cluster",
"Match": {
"Path": "/api/abp/{**everything}"
}
},
"catalog-route": {
"ClusterId": "catalog-cluster",
"Match": {
"Path": "/api/catalog/{**everything}"
}
},
"basket-route": {
"ClusterId": "basket-cluster",
"Match": {
"Path": "/api/basket/{**everything}"
}
},
"ordering-route": {
"ClusterId": "ordering-cluster",
"Match": {
"Path": "/api/ordering/{**everything}"
}
},
"payment-route": {
"ClusterId": "payment-cluster",
"Match": {
"Path": "/api/payment/{**everything}"
}
}
},
"Clusters": {
"account-cluster": {
"Destinations": {
"destination1": {
"Address": "https://localhost:44330"
}
}
},
"administration-cluster": {
"Destinations": {
"destination1": {
"Address": "https://localhost:44353"
}
}
},
"catalog-cluster": {
"Destinations": {
"destination1": {
"Address": "https://localhost:44354"
}
}
},
"basket-cluster": {
"Destinations": {
"destination1": {
"Address": "https://localhost:44355"
}
}
},
"ordering-cluster": {
"Destinations": {
"destination1": {
"Address": "https://localhost:44356"
}
}
},
"payment-cluster": {
"Destinations": {
"destination1": {
"Address": "https://localhost:44357"
}
}
}
}
}
}

Loading…
Cancel
Save