You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
3.0 KiB
88 lines
3.0 KiB
using EShopOnAbp.Shared.Hosting.AspNetCore;
|
|
using EShopOnAbp.Shared.Hosting.Gateways;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Cors;
|
|
using Microsoft.AspNetCore.Rewrite;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Volo.Abp;
|
|
using Volo.Abp.Modularity;
|
|
|
|
namespace EShopOnAbp.WebGateway;
|
|
|
|
[DependsOn(
|
|
typeof(EShopOnAbpSharedHostingGatewaysModule)
|
|
)]
|
|
public class EShopOnAbpWebGatewayModule : AbpModule
|
|
{
|
|
public override void ConfigureServices(ServiceConfigurationContext context)
|
|
{
|
|
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"},
|
|
{"CmskitService", "Cmskit Service API"},
|
|
},
|
|
apiTitle: "Web Gateway"
|
|
);
|
|
|
|
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();
|
|
});
|
|
});
|
|
}
|
|
|
|
public override void OnApplicationInitialization(ApplicationInitializationContext context)
|
|
{
|
|
var app = context.GetApplicationBuilder();
|
|
var env = context.GetEnvironment();
|
|
|
|
if (env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
app.UseCorrelationId();
|
|
app.UseAbpSerilogEnrichers();
|
|
app.UseCors();
|
|
app.UseSwaggerUIWithYarp(context);
|
|
|
|
app.UseRewriter(new RewriteOptions()
|
|
// Regex for "", "/" and "" (whitespace)
|
|
.AddRedirect("^(|\\|\\s+)$", "/swagger"));
|
|
|
|
app.UseRouting();
|
|
app.UseEndpoints(endpoints =>
|
|
{
|
|
endpoints.MapReverseProxy();
|
|
});
|
|
}
|
|
}
|