Browse Source

Merge pull request #6 from abpframework/gterdem/gateway_improvements

EShopOnAbp: Gateway Improvements
gterdem/deployment_k8s
Enis Necipoglu 5 years ago
committed by GitHub
parent
commit
f71838fa70
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 29
      gateways/internal/src/EShopOnAbp.InternalGateway/EShopOnAbpInternalGatewayModule.cs
  2. 13
      gateways/internal/src/EShopOnAbp.InternalGateway/appsettings.json
  3. 26
      gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbpWebPublicGatewayModule.cs
  4. 2
      gateways/web-public/src/EShopOnAbp.WebPublicGateway/appsettings.json
  5. 49
      gateways/web/src/EShopOnAbp.WebGateway/EShopOnAbpWebGatewayModule.cs
  6. 7
      gateways/web/src/EShopOnAbp.WebGateway/appsettings.json
  7. 39
      services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/AdministrationServiceHttpApiHostModule.cs
  8. 7
      services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/appsettings.json
  9. 8
      services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs
  10. 1
      services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/EShopOnAbp.IdentityService.HttpApi.Host.csproj
  11. 40
      services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/IdentityServiceHttpApiHostModule.cs
  12. 7
      services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/appsettings.json
  13. 34
      services/saas/src/EShopOnAbp.SaasService.HttpApi.Host/SaasServiceHttpApiHostModule.cs
  14. 7
      services/saas/src/EShopOnAbp.SaasService.HttpApi.Host/appsettings.json
  15. 1
      shared/EShopOnAbp.Shared.Hosting.AspNetCore/EShopOnAbp.Shared.Hosting.AspNetCore.csproj
  16. 2
      shared/EShopOnAbp.Shared.Hosting.AspNetCore/EShopOnAbpSharedHostingAspNetCoreModule.cs
  17. 42
      shared/EShopOnAbp.Shared.Hosting.AspNetCore/SwaggerConfigurationHelper.cs
  18. 6
      shared/EShopOnAbp.Shared.Hosting.AspNetCore/SwaggerWithAuthConfigurationHelper.cs
  19. 2
      shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbp.Shared.Hosting.Gateways.csproj
  20. 3
      shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbpSharedHostingGatewaysModule.cs
  21. 20
      shared/EShopOnAbp.Shared.Hosting.Gateways/OcelotConfiguration.cs

29
gateways/internal/src/EShopOnAbp.InternalGateway/EShopOnAbpInternalGatewayModule.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.Modularity;
@ -19,18 +21,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<string, string> /* 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)
@ -47,10 +38,18 @@ namespace EShopOnAbp.InternalGateway
app.UseSwagger();
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Internal Gateway API");
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]);
options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]);
var routes = configuration.GetSection("Routes").Get<List<OcelotConfiguration>>();
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(

13
gateways/internal/src/EShopOnAbp.InternalGateway/appsettings.json

@ -2,12 +2,6 @@
"App": {
"SelfUrl": "https://localhost:44371"
},
"AuthServer": {
"Authority": "https://localhost:44330",
"RequireHttpsMetadata": "true",
"SwaggerClientId": "InternalGateway_Swagger",
"SwaggerClientSecret": "1q2w3e*"
},
"Logging": {
"LogLevel": {
"Default": "Information",
@ -18,6 +12,7 @@
"AllowedHosts": "*",
"Routes": [
{
"ServiceName": "Identity Service",
"DownstreamPathTemplate": "/api/identity/{everything}",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
@ -30,6 +25,7 @@
"UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ]
},
{
"ServiceName": "Identity Service",
"DownstreamPathTemplate": "/api/account/{everything}",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
@ -42,6 +38,7 @@
"UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ]
},
{
"ServiceName": "Saas Service",
"DownstreamPathTemplate": "/api/saas/{everything}",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
@ -54,6 +51,7 @@
"UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ]
},
{
"ServiceName": "Administration Service",
"DownstreamPathTemplate": "/api/abp/{everything}",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
@ -66,6 +64,7 @@
"UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ]
},
{
"ServiceName": "Administration Service",
"DownstreamPathTemplate": "/api/feature-management/{everything}",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
@ -78,6 +77,7 @@
"UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ]
},
{
"ServiceName": "Administration Service",
"DownstreamPathTemplate": "/api/permission-management/{everything}",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
@ -90,6 +90,7 @@
"UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ]
},
{
"ServiceName": "Administration Service",
"DownstreamPathTemplate": "/api/setting-management/{everything}",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [

26
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.Modularity;
@ -19,15 +21,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<string, string> /* 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)
@ -44,10 +39,17 @@ namespace EShopOnAbp.WebPublicGateway
app.UseSwagger();
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Web Public Gateway API");
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]);
options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]);
var routes = configuration.GetSection("Routes").Get<List<OcelotConfiguration>>();
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(

2
gateways/web-public/src/EShopOnAbp.WebPublicGateway/appsettings.json

@ -19,6 +19,7 @@
"AllowedHosts": "*",
"Routes": [
{
"ServiceName": "Identity Service",
"DownstreamPathTemplate": "/api/account/{everything}",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
@ -31,6 +32,7 @@
"UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ]
},
{
"ServiceName": "Administration Service",
"DownstreamPathTemplate": "/api/abp/{everything}",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [

49
gateways/web/src/EShopOnAbp.WebGateway/EShopOnAbpWebGatewayModule.cs

@ -8,6 +8,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;
@ -22,37 +24,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<string, string> /* 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)
@ -66,14 +38,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<IConfiguration>();
options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]);
options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]);
var routes = configuration.GetSection("Routes").Get<List<OcelotConfiguration>>();
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(

7
gateways/web/src/EShopOnAbp.WebGateway/appsettings.json

@ -19,6 +19,7 @@
"AllowedHosts": "*",
"Routes": [
{
"ServiceName": "Identity Service",
"DownstreamPathTemplate": "/api/identity/{everything}",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
@ -31,6 +32,7 @@
"UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ]
},
{
"ServiceName": "Identity Service",
"DownstreamPathTemplate": "/api/account/{everything}",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
@ -43,6 +45,7 @@
"UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ]
},
{
"ServiceName": "Saas Service",
"DownstreamPathTemplate": "/api/multi-tenancy/{everything}",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
@ -55,6 +58,7 @@
"UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ]
},
{
"ServiceName": "Administration Service",
"DownstreamPathTemplate": "/api/abp/{everything}",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
@ -67,6 +71,7 @@
"UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ]
},
{
"ServiceName": "Administration Service",
"DownstreamPathTemplate": "/api/feature-management/{everything}",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
@ -79,6 +84,7 @@
"UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ]
},
{
"ServiceName": "Administration Service",
"DownstreamPathTemplate": "/api/permission-management/{everything}",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
@ -91,6 +97,7 @@
"UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ]
},
{
"ServiceName": "Administration Service",
"DownstreamPathTemplate": "/api/setting-management/{everything}",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [

39
services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/AdministrationServiceHttpApiHostModule.cs

@ -1,8 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using EShopOnAbp.AdministrationService.DbMigrations;
using EShopOnAbp.AdministrationService.EntityFrameworkCore;
using EShopOnAbp.SaasService;
using EShopOnAbp.Shared.Hosting.AspNetCore;
using EShopOnAbp.Shared.Hosting.Microservices;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Cors;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Volo.Abp;
@ -31,8 +36,39 @@ namespace EShopOnAbp.AdministrationService
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
JwtBearerConfigurationHelper.Configure(context, "AdministrationService");
SwaggerConfigurationHelper.Configure(context, "Administration Service API");
// SwaggerConfigurationHelper.Configure(context, "Administration Service API");
SwaggerWithAuthConfigurationHelper.Configure(
context: context,
authority: configuration["AuthServer:Authority"],
scopes: new Dictionary<string, string> /* Requested scopes for authorization code request and descriptions for swagger UI only */
{
{"Administration", "Administration Service API"},
},
apiTitle: "Administration Service 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();
});
});
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
@ -45,6 +81,7 @@ namespace EShopOnAbp.AdministrationService
}
app.UseCorrelationId();
app.UseCors();
app.UseAbpRequestLocalization();
app.UseStaticFiles();
app.UseRouting();

7
services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/appsettings.json

@ -1,10 +1,13 @@
{
"App": {
"SelfUrl": "https://localhost:44353"
"SelfUrl": "https://localhost:44353",
"CorsOrigins": "https://localhost:44371,https://localhost:44372,https://localhost:44373"
},
"AuthServer": {
"Authority": "https://localhost:44330",
"RequireHttpsMetadata": "true"
"RequireHttpsMetadata": "true",
"SwaggerClientId": "AdministrationService_Swagger",
"SwaggerClientSecret": "1q2w3e*"
},
"RemoteServices": {
"Default": {

8
services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs

@ -97,10 +97,10 @@ namespace EShopOnAbp.IdentityService.DbMigrations
private async Task CreateSwaggerClientsAsync()
{
await CreateSwaggerClientAsync("InternalGateway",
new[] { "IdentityService", "AdministrationService", "SaasService" });
await CreateSwaggerClientAsync("WebGateway",
new[] { "IdentityService", "AdministrationService", "SaasService" });
await CreateSwaggerClientAsync("IdentityService",
new[] { "IdentityService"});
await CreateSwaggerClientAsync("AdministrationService",
new[] { "AdministrationService" });
await CreateSwaggerClientAsync("WebPublicGateway");
}

1
services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/EShopOnAbp.IdentityService.HttpApi.Host.csproj

@ -13,6 +13,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\shared\EShopOnAbp.Shared.Hosting.Gateways\EShopOnAbp.Shared.Hosting.Gateways.csproj" />
<ProjectReference Include="..\..\..\..\shared\EShopOnAbp.Shared.Hosting.Microservices\EShopOnAbp.Shared.Hosting.Microservices.csproj" />
<ProjectReference Include="..\EShopOnAbp.IdentityService.Application\EShopOnAbp.IdentityService.Application.csproj" />
<ProjectReference Include="..\EShopOnAbp.IdentityService.EntityFrameworkCore\EShopOnAbp.IdentityService.EntityFrameworkCore.csproj" />

40
services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/IdentityServiceHttpApiHostModule.cs

@ -1,7 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using EShopOnAbp.IdentityService.DbMigrations;
using EShopOnAbp.IdentityService.EntityFrameworkCore;
using EShopOnAbp.Shared.Hosting.AspNetCore;
using EShopOnAbp.Shared.Hosting.Gateways;
using EShopOnAbp.Shared.Hosting.Microservices;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Cors;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Volo.Abp;
@ -15,7 +21,8 @@ namespace EShopOnAbp.IdentityService
typeof(EShopOnAbpSharedHostingMicroservicesModule),
typeof(IdentityServiceHttpApiModule),
typeof(IdentityServiceApplicationModule),
typeof(IdentityServiceEntityFrameworkCoreModule)
typeof(IdentityServiceEntityFrameworkCoreModule),
typeof(EShopOnAbpSharedHostingGatewaysModule)
)]
public class IdentityServiceHttpApiHostModule : AbpModule
{
@ -25,7 +32,35 @@ namespace EShopOnAbp.IdentityService
var hostingEnvironment = context.Services.GetHostingEnvironment();
JwtBearerConfigurationHelper.Configure(context, "IdentityService");
SwaggerConfigurationHelper.Configure(context, "Identity Service API");
// SwaggerConfigurationHelper.Configure(context, "Identity Service 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();
});
});
SwaggerWithAuthConfigurationHelper.Configure(
context: context,
authority: configuration["AuthServer:Authority"],
scopes: new Dictionary<string, string> /* Requested scopes for authorization code request and descriptions for swagger UI only */
{
{"IdentityService", "Identity Service API"}
},
apiTitle: "IdentityService Gateway API"
);
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
@ -39,6 +74,7 @@ namespace EShopOnAbp.IdentityService
}
app.UseCorrelationId();
app.UseCors();
app.UseAbpRequestLocalization();
app.UseStaticFiles();
app.UseRouting();

7
services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/appsettings.json

@ -1,10 +1,13 @@
{
"App": {
"SelfUrl": "https://localhost:44351"
"SelfUrl": "https://localhost:44351",
"CorsOrigins": "https://localhost:44371,https://localhost:44372,https://localhost:44373"
},
"AuthServer": {
"Authority": "https://localhost:44330",
"RequireHttpsMetadata": "true"
"RequireHttpsMetadata": "true",
"SwaggerClientId": "IdentityService_Swagger",
"SwaggerClientSecret": "1q2w3e*"
},
"Logging": {
"LogLevel": {

34
services/saas/src/EShopOnAbp.SaasService.HttpApi.Host/SaasServiceHttpApiHostModule.cs

@ -10,6 +10,7 @@ using Microsoft.AspNetCore.DataProtection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using EShopOnAbp.SaasService.EntityFrameworkCore;
using EShopOnAbp.Shared.Hosting.AspNetCore;
using EShopOnAbp.Shared.Hosting.Microservices;
using StackExchange.Redis;
using Microsoft.OpenApi.Models;
@ -34,10 +35,40 @@ namespace EShopOnAbp.SaasService
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
context.Services.AddAbpDbContext<SaasServiceDbContext>();
JwtBearerConfigurationHelper.Configure(context, "SaasService");
SwaggerConfigurationHelper.Configure(context, "Saas Service API");
// SwaggerConfigurationHelper.Configure(context, "Saas Service API");
SwaggerWithAuthConfigurationHelper.Configure(
context: context,
authority: configuration["AuthServer:Authority"],
scopes: new Dictionary<string, string> /* Requested scopes for authorization code request and descriptions for swagger UI only */
{
{"SaasService", "Saas Service API"},
},
apiTitle: "Saas Service 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();
});
});
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
@ -51,6 +82,7 @@ namespace EShopOnAbp.SaasService
}
app.UseCorrelationId();
app.UseCors();
app.UseAbpRequestLocalization();
app.UseStaticFiles();
app.UseRouting();

7
services/saas/src/EShopOnAbp.SaasService.HttpApi.Host/appsettings.json

@ -1,10 +1,13 @@
{
"App": {
"SelfUrl": "https://localhost:44352"
"SelfUrl": "https://localhost:44352",
"CorsOrigins": "https://localhost:44371,https://localhost:44372,https://localhost:44373"
},
"AuthServer": {
"Authority": "https://localhost:44330",
"RequireHttpsMetadata": "true"
"RequireHttpsMetadata": "true",
"SwaggerClientId": "IdentityService_Swagger",
"SwaggerClientSecret": "1q2w3e*"
},
"Logging": {
"LogLevel": {

1
shared/EShopOnAbp.Shared.Hosting.AspNetCore/EShopOnAbp.Shared.Hosting.AspNetCore.csproj

@ -9,6 +9,7 @@
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
<!-- <PackageReference Include="Serilog.Sinks.ElasticSearch" Version="8.4.1" />-->
<PackageReference Include="Volo.Abp.AspNetCore.Serilog" Version="4.4.0" />
<PackageReference Include="Volo.Abp.Swashbuckle" Version="4.4.0" />
</ItemGroup>
<ItemGroup>

2
shared/EShopOnAbp.Shared.Hosting.AspNetCore/EShopOnAbpSharedHostingAspNetCoreModule.cs

@ -1,10 +1,12 @@
using Volo.Abp.AspNetCore.Serilog;
using Volo.Abp.Modularity;
using Volo.Abp.Swashbuckle;
namespace EShopOnAbp.Shared.Hosting.AspNetCore
{
[DependsOn(
typeof(EShopOnAbpSharedHostingModule),
typeof(AbpSwashbuckleModule),
typeof(AbpAspNetCoreSerilogModule)
)]
public class EShopOnAbpSharedHostingAspNetCoreModule : AbpModule

42
shared/EShopOnAbp.Shared.Hosting.Microservices/SwaggerConfigurationHelper.cs → shared/EShopOnAbp.Shared.Hosting.AspNetCore/SwaggerConfigurationHelper.cs

@ -1,22 +1,22 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using Volo.Abp.Modularity;
namespace EShopOnAbp.Shared.Hosting.Microservices
{
public static class SwaggerConfigurationHelper
{
public static void Configure(
ServiceConfigurationContext context,
string apiTitle
)
{
context.Services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new OpenApiInfo {Title = apiTitle, Version = "v1"});
options.DocInclusionPredicate((docName, description) => true);
options.CustomSchemaIds(type => type.FullName);
});
}
}
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using Volo.Abp.Modularity;
namespace EShopOnAbp.Shared.Hosting.AspNetCore
{
public static class SwaggerConfigurationHelper
{
public static void Configure(
ServiceConfigurationContext context,
string apiTitle
)
{
context.Services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new OpenApiInfo {Title = apiTitle, Version = "v1"});
options.DocInclusionPredicate((docName, description) => true);
options.CustomSchemaIds(type => type.FullName);
});
}
}
}

6
shared/EShopOnAbp.Shared.Hosting.Gateways/SwaggerWithAuthConfigurationHelper.cs → shared/EShopOnAbp.Shared.Hosting.AspNetCore/SwaggerWithAuthConfigurationHelper.cs

@ -1,9 +1,9 @@
using Microsoft.Extensions.DependencyInjection;
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using System.Collections.Generic;
using Volo.Abp.Modularity;
namespace EShopOnAbp.Shared.Hosting.Gateways
namespace EShopOnAbp.Shared.Hosting.AspNetCore
{
public static class SwaggerWithAuthConfigurationHelper
{

2
shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbp.Shared.Hosting.Gateways.csproj

@ -7,10 +7,10 @@
<ItemGroup>
<PackageReference Include="Ocelot" Version="17.0.0" />
<PackageReference Include="Ocelot.Provider.Polly" Version="17.0.0" />
<PackageReference Include="Ocelot.Provider.Consul" Version="17.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Volo.Abp.Swashbuckle" Version="4.4.0" />
<PackageReference Include="Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy" Version="4.4.0" />
</ItemGroup>

3
shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbpSharedHostingGatewaysModule.cs

@ -1,6 +1,7 @@
using EShopOnAbp.Shared.Hosting.AspNetCore;
using Microsoft.Extensions.DependencyInjection;
using Ocelot.DependencyInjection;
using Ocelot.Provider.Consul;
using Ocelot.Provider.Polly;
using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy;
using Volo.Abp.Modularity;
@ -10,7 +11,6 @@ namespace EShopOnAbp.Shared.Hosting.Gateways
{
[DependsOn(
typeof(EShopOnAbpSharedHostingAspNetCoreModule),
typeof(AbpSwashbuckleModule),
typeof(AbpAspNetCoreMvcUiMultiTenancyModule)
)]
public class EShopOnAbpSharedHostingGatewaysModule : AbpModule
@ -20,6 +20,7 @@ namespace EShopOnAbp.Shared.Hosting.Gateways
var configuration = context.Services.GetConfiguration();
context.Services.AddOcelot(configuration)
.AddConsul()
.AddPolly();
}
}

20
shared/EShopOnAbp.Shared.Hosting.Gateways/OcelotConfiguration.cs

@ -0,0 +1,20 @@
using System.Collections.Generic;
namespace EShopOnAbp.Shared.Hosting.Gateways
{
public class OcelotConfiguration
{
public string ServiceName { 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; }
}
}
Loading…
Cancel
Save