diff --git a/gateways/internal/src/EShopOnAbp.InternalGateway/EShopOnAbpInternalGatewayModule.cs b/gateways/internal/src/EShopOnAbp.InternalGateway/EShopOnAbpInternalGatewayModule.cs index d6fd6028..06558c29 100644 --- a/gateways/internal/src/EShopOnAbp.InternalGateway/EShopOnAbpInternalGatewayModule.cs +++ b/gateways/internal/src/EShopOnAbp.InternalGateway/EShopOnAbpInternalGatewayModule.cs @@ -8,6 +8,8 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Ocelot.Middleware; using System.Collections.Generic; +using System.Linq; +using EShopOnAbp.Shared.Hosting.AspNetCore; using Volo.Abp; using Volo.Abp.Modularity; @@ -25,18 +27,7 @@ namespace EShopOnAbp.InternalGateway { var configuration = context.Services.GetConfiguration(); var hostingEnvironment = context.Services.GetHostingEnvironment(); - - SwaggerWithAuthConfigurationHelper.Configure( - context: context, - authority: configuration["AuthServer:Authority"], - scopes: new Dictionary /* Requested scopes for authorization code request and descriptions for swagger UI only */ - { - {"IdentityService", "Identity Service API"}, - {"AdministrationService", "Administration Service API"}, - {"SaasService", "Saas Service API"}, - }, - apiTitle: "Internal Gateway API" - ); + SwaggerConfigurationHelper.Configure(context, "Internal Gateway"); } public override void OnApplicationInitialization(ApplicationInitializationContext context) @@ -53,10 +44,18 @@ namespace EShopOnAbp.InternalGateway app.UseSwagger(); app.UseSwaggerUI(options => { - options.SwaggerEndpoint("/swagger/v1/swagger.json", "Internal Gateway API"); var configuration = context.ServiceProvider.GetRequiredService(); - options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]); - options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]); + var routes = configuration.GetSection("Routes").Get>(); + + foreach (var config in routes.GroupBy(t => t.ServiceName).Select(r => r.First()).Distinct()) + { + var url = + $"{config.DownstreamScheme}://{config.DownstreamHostAndPorts.FirstOrDefault()?.Host}:{config.DownstreamHostAndPorts.FirstOrDefault()?.Port}"; + + options.SwaggerEndpoint($"{url}/swagger/v1/swagger.json", $"{config.ServiceName} API"); + options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]); + options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]); + } }); app.UseAbpSerilogEnrichers(); app.MapWhen( diff --git a/gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbpWebPublicGatewayModule.cs b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbpWebPublicGatewayModule.cs index 71917b2b..4aa892a3 100644 --- a/gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbpWebPublicGatewayModule.cs +++ b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbpWebPublicGatewayModule.cs @@ -5,6 +5,8 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Ocelot.Middleware; using System.Collections.Generic; +using System.Linq; +using EShopOnAbp.Shared.Hosting.AspNetCore; using Volo.Abp; using Volo.Abp.Account; using Volo.Abp.Modularity; @@ -21,15 +23,8 @@ namespace EShopOnAbp.WebPublicGateway { var configuration = context.Services.GetConfiguration(); var hostingEnvironment = context.Services.GetHostingEnvironment(); - - SwaggerWithAuthConfigurationHelper.Configure( - context: context, - authority: configuration["AuthServer:Authority"], - scopes: new Dictionary /* Requested scopes for authorization code request and descriptions for swagger UI only */ - { - }, - apiTitle: "WebPublic Gateway API" - ); + + SwaggerConfigurationHelper.Configure(context, "WebPublic Gateway"); } public override void OnApplicationInitialization(ApplicationInitializationContext context) @@ -46,10 +41,17 @@ namespace EShopOnAbp.WebPublicGateway app.UseSwagger(); app.UseSwaggerUI(options => { - options.SwaggerEndpoint("/swagger/v1/swagger.json", "Web Public Gateway API"); var configuration = context.ServiceProvider.GetRequiredService(); - options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]); - options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]); + var routes = configuration.GetSection("Routes").Get>(); + foreach (var config in routes.GroupBy(t => t.ServiceName).Select(r => r.First()).Distinct()) + { + var url = + $"{config.DownstreamScheme}://{config.DownstreamHostAndPorts.FirstOrDefault()?.Host}:{config.DownstreamHostAndPorts.FirstOrDefault()?.Port}"; + + options.SwaggerEndpoint($"{url}/swagger/v1/swagger.json", $"{config.ServiceName} API"); + options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]); + options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]); + } }); app.UseAbpSerilogEnrichers(); app.MapWhen( diff --git a/gateways/web/src/EShopOnAbp.WebGateway/EShopOnAbpWebGatewayModule.cs b/gateways/web/src/EShopOnAbp.WebGateway/EShopOnAbpWebGatewayModule.cs index 680ca239..9f23ad35 100644 --- a/gateways/web/src/EShopOnAbp.WebGateway/EShopOnAbpWebGatewayModule.cs +++ b/gateways/web/src/EShopOnAbp.WebGateway/EShopOnAbpWebGatewayModule.cs @@ -11,6 +11,8 @@ using Ocelot.Middleware; using System; using System.Collections.Generic; using System.Linq; +using EShopOnAbp.Shared.Hosting.AspNetCore; +using Microsoft.OpenApi.Models; using Volo.Abp; using Volo.Abp.Modularity; @@ -28,37 +30,7 @@ namespace EShopOnAbp.WebGateway { var configuration = context.Services.GetConfiguration(); var hostingEnvironment = context.Services.GetHostingEnvironment(); - - SwaggerWithAuthConfigurationHelper.Configure( - context: context, - authority: configuration["AuthServer:Authority"], - scopes: new Dictionary /* Requested scopes for authorization code request and descriptions for swagger UI only */ - { - {"IdentityService", "Identity Service API"}, - {"AdministrationService", "Administration Service API"}, - {"SaasService", "Saas Service API"}, - }, - apiTitle: "Web Gateway API" - ); - - context.Services.AddCors(options => - { - options.AddDefaultPolicy(builder => - { - builder - .WithOrigins( - configuration["App:CorsOrigins"] - .Split(",", StringSplitOptions.RemoveEmptyEntries) - .Select(o => o.Trim().RemovePostFix("/")) - .ToArray() - ) - .WithAbpExposedHeaders() - .SetIsOriginAllowedToAllowWildcardSubdomains() - .AllowAnyHeader() - .AllowAnyMethod() - .AllowCredentials(); - }); - }); + SwaggerConfigurationHelper.Configure(context, "Web Gateway"); } public override void OnApplicationInitialization(ApplicationInitializationContext context) @@ -72,14 +44,21 @@ namespace EShopOnAbp.WebGateway } app.UseCorrelationId(); - app.UseCors(); app.UseSwagger(); app.UseSwaggerUI(options => { - options.SwaggerEndpoint("/swagger/v1/swagger.json", "Web Gateway API"); var configuration = context.ServiceProvider.GetRequiredService(); - options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]); - options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]); + var routes = configuration.GetSection("Routes").Get>(); + + foreach (var config in routes.GroupBy(t => t.ServiceName).Select(r => r.First()).Distinct()) + { + var url = + $"{config.DownstreamScheme}://{config.DownstreamHostAndPorts.FirstOrDefault()?.Host}:{config.DownstreamHostAndPorts.FirstOrDefault()?.Port}"; + + options.SwaggerEndpoint($"{url}/swagger/v1/swagger.json", $"{config.ServiceName} API"); + options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]); + options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]); + } }); app.UseAbpSerilogEnrichers(); app.MapWhen(