|
|
|
@ -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<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")); |
|
|
|
// 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<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.ConfigureSwaggerUIWithYarp(context); |
|
|
|
|
|
|
|
app.UseRewriter(new RewriteOptions() |
|
|
|
// Regex for "", "/" and "" (whitespace)
|
|
|
|
.AddRedirect("^(|\\|\\s+)$", "/swagger")); |
|
|
|
|
|
|
|
app.UseRouting(); |
|
|
|
app.UseEndpoints(endpoints => |
|
|
|
{ |
|
|
|
|