committed by
GitHub
12 changed files with 261 additions and 298 deletions
@ -1,113 +0,0 @@ |
|||
{ |
|||
"GlobalConfiguration": { |
|||
"BaseUrl": "https://localhost:44373" |
|||
}, |
|||
"Routes": [ |
|||
{ |
|||
"ServiceKey": "Account Service", |
|||
"DownstreamPathTemplate": "/api/account/{everything}", |
|||
"DownstreamScheme": "https", |
|||
"DownstreamHostAndPorts": [ |
|||
{ |
|||
"Host": "localhost", |
|||
"Port": 44330 |
|||
} |
|||
], |
|||
"UpstreamPathTemplate": "/api/account/{everything}", |
|||
"UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] |
|||
}, |
|||
{ |
|||
"ServiceKey": "Administration Service", |
|||
"DownstreamPathTemplate": "/api/abp/{everything}", |
|||
"DownstreamScheme": "https", |
|||
"DownstreamHostAndPorts": [ |
|||
{ |
|||
"Host": "localhost", |
|||
"Port": 44353 |
|||
} |
|||
], |
|||
"UpstreamPathTemplate": "/api/abp/{everything}", |
|||
"UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ], |
|||
"QoSOptions": { |
|||
"ExceptionsAllowedBeforeBreaking": 3, |
|||
"DurationOfBreak": 3000, |
|||
"TimeoutValue": 2500 |
|||
} |
|||
}, |
|||
{ |
|||
"ServiceKey": "Catalog Service", |
|||
"DownstreamPathTemplate": "/api/catalog/{everything}", |
|||
"DownstreamScheme": "https", |
|||
"DownstreamHostAndPorts": [ |
|||
{ |
|||
"Host": "localhost", |
|||
"Port": 44354 |
|||
} |
|||
], |
|||
"UpstreamPathTemplate": "/api/catalog/{everything}", |
|||
"UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ], |
|||
"QoSOptions": { |
|||
"ExceptionsAllowedBeforeBreaking": 3, |
|||
"DurationOfBreak": 3000, |
|||
"TimeoutValue": 2500 |
|||
} |
|||
}, |
|||
{ |
|||
"ServiceKey": "Catalog Service", |
|||
"DownstreamPathTemplate": "/product-images/{everything}", |
|||
"DownstreamScheme": "https", |
|||
"DownstreamHostAndPorts": [ |
|||
{ |
|||
"Host": "localhost", |
|||
"Port": 44354 |
|||
} |
|||
], |
|||
"UpstreamPathTemplate": "/product-images/{everything}", |
|||
"UpstreamHttpMethod": [ "Get" ] |
|||
}, |
|||
{ |
|||
"ServiceKey": "Basket Service", |
|||
"DownstreamPathTemplate": "/api/basket/{everything}", |
|||
"DownstreamScheme": "https", |
|||
"DownstreamHostAndPorts": [ |
|||
{ |
|||
"Host": "localhost", |
|||
"Port": 44355 |
|||
} |
|||
], |
|||
"UpstreamPathTemplate": "/api/basket/{everything}", |
|||
"UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ], |
|||
"QoSOptions": { |
|||
"ExceptionsAllowedBeforeBreaking": 3, |
|||
"DurationOfBreak": 3000, |
|||
"TimeoutValue": 2500 |
|||
} |
|||
}, |
|||
{ |
|||
"ServiceKey": "Ordering Service", |
|||
"DownstreamPathTemplate": "/api/ordering/{everything}", |
|||
"DownstreamScheme": "https", |
|||
"DownstreamHostAndPorts": [ |
|||
{ |
|||
"Host": "localhost", |
|||
"Port": 44356 |
|||
} |
|||
], |
|||
"UpstreamPathTemplate": "/api/ordering/{everything}", |
|||
"UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] |
|||
}, |
|||
{ |
|||
"ServiceKey": "Payment Service", |
|||
"DownstreamPathTemplate": "/api/payment/{everything}", |
|||
"DownstreamScheme": "https", |
|||
"DownstreamHostAndPorts": [ |
|||
{ |
|||
"Host": "localhost", |
|||
"Port": 44357 |
|||
} |
|||
], |
|||
"UpstreamPathTemplate": "/api/payment/{everything}", |
|||
"UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] |
|||
} |
|||
] |
|||
} |
|||
@ -0,0 +1,100 @@ |
|||
{ |
|||
"ReverseProxy": { |
|||
"Routes": { |
|||
"Account Service": { |
|||
"ClusterId": "account-cluster", |
|||
"Match": { |
|||
"Path": "/api/account/{**everything}" |
|||
} |
|||
}, |
|||
"Administration Service": { |
|||
"ClusterId": "administration-cluster", |
|||
"Match": { |
|||
"Path": "/api/abp/{**everything}" |
|||
} |
|||
}, |
|||
"Catalog Service": { |
|||
"ClusterId": "catalog-cluster", |
|||
"Match": { |
|||
"Path": "/api/catalog/{**everything}" |
|||
} |
|||
}, |
|||
"Basket Service": { |
|||
"ClusterId": "basket-cluster", |
|||
"Match": { |
|||
"Path": "/api/basket/{**everything}" |
|||
} |
|||
}, |
|||
"Ordering Service": { |
|||
"ClusterId": "ordering-cluster", |
|||
"Match": { |
|||
"Path": "/api/ordering/{**everything}" |
|||
} |
|||
}, |
|||
"Payment Service": { |
|||
"ClusterId": "payment-cluster", |
|||
"Match": { |
|||
"Path": "/api/payment/{**everything}" |
|||
} |
|||
}, |
|||
"product-picture-route": { |
|||
"ClusterId": "product-picture-cluster", |
|||
"Match": { |
|||
"Path": "/product-images/{**everything}", |
|||
"Methods" : [ "GET" ] |
|||
} |
|||
} |
|||
}, |
|||
"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" |
|||
} |
|||
} |
|||
}, |
|||
"product-picture-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" |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,90 +0,0 @@ |
|||
{ |
|||
"GlobalConfiguration": { |
|||
"BaseUrl": "https://localhost:44372" |
|||
}, |
|||
"Routes": [ |
|||
{ |
|||
"ServiceKey": "Identity Service", |
|||
"DownstreamPathTemplate": "/api/identity/{everything}", |
|||
"DownstreamScheme": "https", |
|||
"DownstreamHostAndPorts": [ |
|||
{ |
|||
"Host": "localhost", |
|||
"Port": 44351 |
|||
} |
|||
], |
|||
"UpstreamPathTemplate": "/api/identity/{everything}", |
|||
"UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] |
|||
}, |
|||
{ |
|||
"ServiceKey": "Account Service", |
|||
"DownstreamPathTemplate": "/api/account/{everything}", |
|||
"DownstreamScheme": "https", |
|||
"DownstreamHostAndPorts": [ |
|||
{ |
|||
"Host": "localhost", |
|||
"Port": 44330 |
|||
} |
|||
], |
|||
"UpstreamPathTemplate": "/api/account/{everything}", |
|||
"UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] |
|||
}, |
|||
{ |
|||
"ServiceKey": "Administration Service", |
|||
"DownstreamPathTemplate": "/api/abp/{everything}", |
|||
"DownstreamScheme": "https", |
|||
"DownstreamHostAndPorts": [ |
|||
{ |
|||
"Host": "localhost", |
|||
"Port": 44353 |
|||
} |
|||
], |
|||
"UpstreamPathTemplate": "/api/abp/{everything}", |
|||
"UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ], |
|||
"QoSOptions": { |
|||
"ExceptionsAllowedBeforeBreaking": 3, |
|||
"DurationOfBreak": 5000, |
|||
"TimeoutValue": 2500 |
|||
} |
|||
}, |
|||
{ |
|||
"ServiceKey": "Administration Service", |
|||
"DownstreamPathTemplate": "/api/feature-management/{everything}", |
|||
"DownstreamScheme": "https", |
|||
"DownstreamHostAndPorts": [ |
|||
{ |
|||
"Host": "localhost", |
|||
"Port": 44353 |
|||
} |
|||
], |
|||
"UpstreamPathTemplate": "/api/feature-management/{everything}", |
|||
"UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] |
|||
}, |
|||
{ |
|||
"ServiceKey": "Administration Service", |
|||
"DownstreamPathTemplate": "/api/permission-management/{everything}", |
|||
"DownstreamScheme": "https", |
|||
"DownstreamHostAndPorts": [ |
|||
{ |
|||
"Host": "localhost", |
|||
"Port": 44353 |
|||
} |
|||
], |
|||
"UpstreamPathTemplate": "/api/permission-management/{everything}", |
|||
"UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] |
|||
}, |
|||
{ |
|||
"ServiceKey": "Administration Service", |
|||
"DownstreamPathTemplate": "/api/setting-management/{everything}", |
|||
"DownstreamScheme": "https", |
|||
"DownstreamHostAndPorts": [ |
|||
{ |
|||
"Host": "localhost", |
|||
"Port": 44353 |
|||
} |
|||
], |
|||
"UpstreamPathTemplate": "/api/setting-management/{everything}", |
|||
"UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] |
|||
} |
|||
] |
|||
} |
|||
@ -0,0 +1,86 @@ |
|||
{ |
|||
"ReverseProxy": { |
|||
"Routes": { |
|||
"Account Service": { |
|||
"ClusterId": "account-cluster", |
|||
"Match": { |
|||
"Path": "/api/account/{**everything}" |
|||
} |
|||
}, |
|||
"Identity Service": { |
|||
"ClusterId": "identity-cluster", |
|||
"Match": { |
|||
"Path": "/api/identity/{**everything}" |
|||
} |
|||
}, |
|||
"Administration Service": { |
|||
"ClusterId": "administration-cluster", |
|||
"Match": { |
|||
"Path": "/api/abp/{**everything}" |
|||
} |
|||
}, |
|||
"feature-management-route": { |
|||
"ClusterId": "feature-management-cluster", |
|||
"Match": { |
|||
"Path": "/api/feature-management/{**everything}" |
|||
} |
|||
}, |
|||
"permission-management-route": { |
|||
"ClusterId": "permission-management-cluster", |
|||
"Match": { |
|||
"Path": "/api/permission-management/{**everything}" |
|||
} |
|||
}, |
|||
"setting-management-route": { |
|||
"ClusterId": "setting-management-cluster", |
|||
"Match": { |
|||
"Path": "/api/setting-management/{**everything}" |
|||
} |
|||
} |
|||
}, |
|||
"Clusters": { |
|||
"account-cluster": { |
|||
"Destinations": { |
|||
"destination1": { |
|||
"Address": "https://localhost:44330" |
|||
} |
|||
} |
|||
}, |
|||
"identity-cluster": { |
|||
"Destinations": { |
|||
"destination1": { |
|||
"Address": "https://localhost:44351" |
|||
} |
|||
} |
|||
}, |
|||
"administration-cluster": { |
|||
"Destinations": { |
|||
"destination1": { |
|||
"Address": "https://localhost:44353" |
|||
} |
|||
} |
|||
}, |
|||
"feature-management-cluster": { |
|||
"Destinations": { |
|||
"destination1": { |
|||
"Address": "https://localhost:44353" |
|||
} |
|||
} |
|||
}, |
|||
"permission-management-cluster": { |
|||
"Destinations": { |
|||
"destination1": { |
|||
"Address": "https://localhost:44353" |
|||
} |
|||
} |
|||
}, |
|||
"setting-management-cluster": { |
|||
"Destinations": { |
|||
"destination1": { |
|||
"Address": "https://localhost:44353" |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,24 +1,20 @@ |
|||
using EShopOnAbp.Shared.Hosting.AspNetCore; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Ocelot.DependencyInjection; |
|||
using Ocelot.Provider.Polly; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace EShopOnAbp.Shared.Hosting.Gateways |
|||
{ |
|||
[DependsOn( |
|||
typeof(EShopOnAbpSharedHostingAspNetCoreModule), |
|||
typeof(AbpAspNetCoreMvcUiMultiTenancyModule) |
|||
typeof(EShopOnAbpSharedHostingAspNetCoreModule) |
|||
)] |
|||
public class EShopOnAbpSharedHostingGatewaysModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
var configuration = context.Services.GetConfiguration(); |
|||
|
|||
context.Services.AddOcelot(configuration) |
|||
.AddPolly(); |
|||
|
|||
context.Services.AddReverseProxy() |
|||
.LoadFromConfig(configuration.GetSection("ReverseProxy")); |
|||
} |
|||
} |
|||
} |
|||
@ -1,20 +0,0 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace EShopOnAbp.Shared.Hosting.Gateways |
|||
{ |
|||
public class OcelotConfiguration |
|||
{ |
|||
public string ServiceKey { get; set; } |
|||
public string DownstreamPathTemplate { get; set; } |
|||
public string DownstreamScheme { get; set; } |
|||
public string UpstreamPathTemplate { get; set; } |
|||
public List<string> UpstreamHttpMethod { get; set; } |
|||
public List<HostAndPort> DownstreamHostAndPorts { get; set; } |
|||
} |
|||
|
|||
public class HostAndPort |
|||
{ |
|||
public string Host { get; set; } |
|||
public int Port { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,52 @@ |
|||
using System.Linq; |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Microsoft.Extensions.Configuration; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Logging; |
|||
using Volo.Abp; |
|||
using Yarp.ReverseProxy.Configuration; |
|||
|
|||
namespace EShopOnAbp.Shared.Hosting.Gateways; |
|||
|
|||
public static class YarpSwaggerUIBuilderExtensions |
|||
{ |
|||
public static IApplicationBuilder ConfigureSwaggerUIWithYarp(this IApplicationBuilder app, |
|||
ApplicationInitializationContext context) |
|||
{ |
|||
app.UseSwagger(); |
|||
app.UseSwaggerUI(options => |
|||
{ |
|||
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>(); |
|||
var logger = context.ServiceProvider.GetRequiredService<ILogger<ApplicationInitializationContext>>(); |
|||
var proxyConfigProvider = context.ServiceProvider.GetRequiredService<IProxyConfigProvider>(); |
|||
var yarpConfig = proxyConfigProvider.GetConfig(); |
|||
|
|||
var routedClusters = yarpConfig.Clusters |
|||
.SelectMany(t => t.Destinations, |
|||
(clusterId, destination) => new {clusterId.ClusterId, destination.Value}); |
|||
|
|||
var groupedClusters = routedClusters |
|||
.GroupBy(q => q.Value.Address) |
|||
.Select(t => t.First()) |
|||
.Distinct() |
|||
.ToList(); |
|||
|
|||
foreach (var clusterGroup in groupedClusters) |
|||
{ |
|||
var routeConfig = yarpConfig.Routes.FirstOrDefault(q => |
|||
q.ClusterId == clusterGroup.ClusterId); |
|||
if (routeConfig == null) |
|||
{ |
|||
logger.LogWarning($"Swagger UI: Couldn't find route configuration for {clusterGroup.ClusterId}..."); |
|||
continue; |
|||
} |
|||
|
|||
options.SwaggerEndpoint($"{clusterGroup.Value.Address}/swagger/v1/swagger.json", $"{routeConfig.RouteId} API"); |
|||
options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]); |
|||
options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]); |
|||
} |
|||
}); |
|||
|
|||
return app; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue