diff --git a/gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbpWebPublicGatewayModule.cs b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbpWebPublicGatewayModule.cs index 00f4da4f..6609c638 100644 --- a/gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbpWebPublicGatewayModule.cs +++ b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbpWebPublicGatewayModule.cs @@ -1,11 +1,8 @@ using EShopOnAbp.Shared.Hosting.Gateways; using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using Ocelot.Middleware; using System.Collections.Generic; -using System.Linq; using EShopOnAbp.Shared.Hosting.AspNetCore; using Microsoft.AspNetCore.Http; using Volo.Abp; @@ -24,24 +21,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 /* 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 /* 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")); + // context.Services.AddReverseProxy() + // .LoadFromConfig(configuration.GetSection("ReverseProxy")); } public override void OnApplicationInitialization(ApplicationInitializationContext context) @@ -56,45 +53,12 @@ public class EShopOnAbpWebPublicGatewayModule : AbpModule app.UseCorrelationId(); app.UseAbpSerilogEnrichers(); - // app.UseSwagger(); - // app.UseSwaggerUI(options => - // { - // var configuration = context.ServiceProvider.GetRequiredService(); - // var routes = configuration.GetSection("Routes").Get>(); - // 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.ConfigureSwaggerUIWithYarp(context); + + app.UseRewriter(new RewriteOptions() + // Regex for "", "/" and "" (whitespace) + .AddRedirect("^(|\\|\\s+)$", "/swagger")); + app.UseRouting(); app.UseEndpoints(endpoints => { diff --git a/gateways/web/src/EShopOnAbp.WebGateway/EShopOnAbpWebGatewayModule.cs b/gateways/web/src/EShopOnAbp.WebGateway/EShopOnAbpWebGatewayModule.cs index 232fafb2..ae4cb249 100644 --- a/gateways/web/src/EShopOnAbp.WebGateway/EShopOnAbpWebGatewayModule.cs +++ b/gateways/web/src/EShopOnAbp.WebGateway/EShopOnAbpWebGatewayModule.cs @@ -4,7 +4,6 @@ using Microsoft.AspNetCore.Cors; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using Ocelot.Middleware; using System; using System.Collections.Generic; using System.Linq; @@ -71,39 +70,15 @@ public class EShopOnAbpWebGatewayModule : AbpModule { app.UseDeveloperExceptionPage(); } - app.UseCorrelationId(); app.UseAbpSerilogEnrichers(); app.UseCors(); - app.UseSwagger(); - app.UseSwaggerUI(options => - { - var configuration = context.ServiceProvider.GetRequiredService(); - var routes = configuration.GetSection("Routes").Get>(); - 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.ConfigureSwaggerUIWithYarp(context); app.UseRewriter(new RewriteOptions() // Regex for "", "/" and "" (whitespace) .AddRedirect("^(|\\|\\s+)$", "/swagger")); - app.UseOcelot().Wait(); + // app.UseOcelot().Wait(); } } \ No newline at end of file