From 875cdc414f2b3383d0ef2a679c6f63a5e1f111b5 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Wed, 30 Jun 2021 13:00:03 +0300 Subject: [PATCH] Added Web-Public Gateway --- EShopOnAbp.sln | 7 ++ .../EShopOnAbp.WebPublicGateway.sln | 32 +++++++++ .../Controllers/HomeController.cs | 13 ++++ .../EShopOnAbp.WebPublicGateway.csproj | 22 ++++++ .../EShopOnAbpWebPublicGatewayModule.cs | 67 +++++++++++++++++++ .../EShopOnAbp.WebPublicGateway/Program.cs | 46 +++++++++++++ .../Properties/launchSettings.json | 29 ++++++++ .../EShopOnAbp.WebPublicGateway/Startup.cs | 19 ++++++ .../appsettings.Development.json | 9 +++ .../appsettings.json | 55 +++++++++++++++ .../DbMigrations/IdentityServerDataSeeder.cs | 2 +- .../appsettings.json | 4 +- 12 files changed, 302 insertions(+), 3 deletions(-) create mode 100644 gateways/web-public/EShopOnAbp.WebPublicGateway.sln create mode 100644 gateways/web-public/src/EShopOnAbp.WebPublicGateway/Controllers/HomeController.cs create mode 100644 gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbp.WebPublicGateway.csproj create mode 100644 gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbpWebPublicGatewayModule.cs create mode 100644 gateways/web-public/src/EShopOnAbp.WebPublicGateway/Program.cs create mode 100644 gateways/web-public/src/EShopOnAbp.WebPublicGateway/Properties/launchSettings.json create mode 100644 gateways/web-public/src/EShopOnAbp.WebPublicGateway/Startup.cs create mode 100644 gateways/web-public/src/EShopOnAbp.WebPublicGateway/appsettings.Development.json create mode 100644 gateways/web-public/src/EShopOnAbp.WebPublicGateway/appsettings.json diff --git a/EShopOnAbp.sln b/EShopOnAbp.sln index e5ac894c..5bafa2d0 100644 --- a/EShopOnAbp.sln +++ b/EShopOnAbp.sln @@ -33,6 +33,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EShopOnAbp.InternalGateway" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EShopOnAbp.WebGateway", "gateways\web\src\EShopOnAbp.WebGateway\EShopOnAbp.WebGateway.csproj", "{5D653BE4-7653-4684-B9F0-9A9B955093E5}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EShopOnAbp.WebPublicGateway", "gateways\web-public\src\EShopOnAbp.WebPublicGateway\EShopOnAbp.WebPublicGateway.csproj", "{2E0B715C-3AAD-47B3-B2EB-D34CB24CBEFA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -83,6 +85,10 @@ Global {5D653BE4-7653-4684-B9F0-9A9B955093E5}.Debug|Any CPU.Build.0 = Debug|Any CPU {5D653BE4-7653-4684-B9F0-9A9B955093E5}.Release|Any CPU.ActiveCfg = Release|Any CPU {5D653BE4-7653-4684-B9F0-9A9B955093E5}.Release|Any CPU.Build.0 = Release|Any CPU + {2E0B715C-3AAD-47B3-B2EB-D34CB24CBEFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2E0B715C-3AAD-47B3-B2EB-D34CB24CBEFA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2E0B715C-3AAD-47B3-B2EB-D34CB24CBEFA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2E0B715C-3AAD-47B3-B2EB-D34CB24CBEFA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -99,6 +105,7 @@ Global {590B609C-5887-4896-9FC5-5E54A2658B18} = {B8B59303-2178-459B-91A8-DF353044E090} {857EE54A-6116-46AA-AB34-50B19E51DB3B} = {1484E912-DCF3-4568-A72C-4C7622104DB8} {5D653BE4-7653-4684-B9F0-9A9B955093E5} = {1484E912-DCF3-4568-A72C-4C7622104DB8} + {2E0B715C-3AAD-47B3-B2EB-D34CB24CBEFA} = {1484E912-DCF3-4568-A72C-4C7622104DB8} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {26F82565-C6A4-439D-93A4-3251E3E7D5B0} diff --git a/gateways/web-public/EShopOnAbp.WebPublicGateway.sln b/gateways/web-public/EShopOnAbp.WebPublicGateway.sln new file mode 100644 index 00000000..1d2bcec3 --- /dev/null +++ b/gateways/web-public/EShopOnAbp.WebPublicGateway.sln @@ -0,0 +1,32 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31320.298 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{138BBFFC-09B9-49FB-9C57-E25327CCE0C1}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{A5E7F07B-7A5D-416D-A9E0-2009A48CBE2A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EShopOnAbp.WebPublicGateway", "src\EShopOnAbp.WebPublicGateway\EShopOnAbp.WebPublicGateway.csproj", "{C3A2AC7A-A50C-4C80-BE68-7FBBAD09D981}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C3A2AC7A-A50C-4C80-BE68-7FBBAD09D981}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C3A2AC7A-A50C-4C80-BE68-7FBBAD09D981}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C3A2AC7A-A50C-4C80-BE68-7FBBAD09D981}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C3A2AC7A-A50C-4C80-BE68-7FBBAD09D981}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {C3A2AC7A-A50C-4C80-BE68-7FBBAD09D981} = {138BBFFC-09B9-49FB-9C57-E25327CCE0C1} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {1753A143-A9EF-43ED-970D-C71BAD179AE6} + EndGlobalSection +EndGlobal diff --git a/gateways/web-public/src/EShopOnAbp.WebPublicGateway/Controllers/HomeController.cs b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/Controllers/HomeController.cs new file mode 100644 index 00000000..fc0b6b82 --- /dev/null +++ b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/Controllers/HomeController.cs @@ -0,0 +1,13 @@ +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc; + +namespace EShopOnAbp.WebPublicGateway.Controllers +{ + public class HomeController : AbpController + { + public ActionResult Index() + { + return Redirect("/swagger"); + } + } +} diff --git a/gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbp.WebPublicGateway.csproj b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbp.WebPublicGateway.csproj new file mode 100644 index 00000000..b715801b --- /dev/null +++ b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbp.WebPublicGateway.csproj @@ -0,0 +1,22 @@ + + + + net5.0 + + + + + + + + + + + + + + + + + + diff --git a/gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbpWebPublicGatewayModule.cs b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbpWebPublicGatewayModule.cs new file mode 100644 index 00000000..c559e959 --- /dev/null +++ b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbpWebPublicGatewayModule.cs @@ -0,0 +1,67 @@ +using System.Collections.Generic; +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 Volo.Abp; +using Volo.Abp.Account; +using Volo.Abp.Modularity; + +namespace EShopOnAbp.WebPublicGateway +{ + [DependsOn( + typeof(EShopOnAbpSharedHostingGatewaysModule), + typeof(AbpAccountHttpApiModule) +)] + public class EShopOnAbpWebPublicGatewayModule : AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + 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" + ); + } + + public override void OnApplicationInitialization(ApplicationInitializationContext context) + { + var app = context.GetApplicationBuilder(); + var env = context.GetEnvironment(); + + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseCorrelationId(); + 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"]); + }); + app.UseAbpSerilogEnrichers(); + app.MapWhen( + ctx => ctx.Request.Path.ToString().StartsWith("/api/abp/api-definition") || + ctx.Request.Path.ToString().TrimEnd('/').Equals(""), + app2 => + { + app2.UseRouting(); + app2.UseConfiguredEndpoints(); + } + ); + app.UseOcelot().Wait(); + } + } +} diff --git a/gateways/web-public/src/EShopOnAbp.WebPublicGateway/Program.cs b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/Program.cs new file mode 100644 index 00000000..afc753a5 --- /dev/null +++ b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/Program.cs @@ -0,0 +1,46 @@ +using System; +using System.Threading.Tasks; +using EShopOnAbp.Shared.Hosting.AspNetCore; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Serilog; + +namespace EShopOnAbp.WebPublicGateway +{ + public class Program + { + public static async Task Main(string[] args) + { + var assemblyName = typeof(Program).Assembly.GetName().Name; + + SerilogConfigurationHelper.Configure(assemblyName); + + try + { + Log.Information($"Starting {assemblyName}."); + await CreateHostBuilder(args).Build().RunAsync(); + return 0; + } + catch (Exception ex) + { + Log.Fatal(ex, $"{assemblyName} terminated unexpectedly!"); + return 1; + } + finally + { + Log.CloseAndFlush(); + } + } + + internal static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureAppConfiguration(build => + { + build.AddJsonFile("appsettings.secrets.json", optional: true); + }) + .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); }) + .UseAutofac() + .UseSerilog(); + } +} diff --git a/gateways/web-public/src/EShopOnAbp.WebPublicGateway/Properties/launchSettings.json b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/Properties/launchSettings.json new file mode 100644 index 00000000..3fe9e119 --- /dev/null +++ b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/Properties/launchSettings.json @@ -0,0 +1,29 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "https://localhost:44373", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "EShopOnAbp.PublicWebGateway": { + "commandName": "Project", + "dotnetRunMessages": "true", + "launchBrowser": true, + "applicationUrl": "https://localhost:44373", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/gateways/web-public/src/EShopOnAbp.WebPublicGateway/Startup.cs b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/Startup.cs new file mode 100644 index 00000000..17c2b98a --- /dev/null +++ b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/Startup.cs @@ -0,0 +1,19 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.DependencyInjection; + +namespace EShopOnAbp.WebPublicGateway +{ + public class Startup + { + public void ConfigureServices(IServiceCollection services) + { + services.AddApplication(); + } + + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + app.InitializeApplication(); + } + } +} diff --git a/gateways/web-public/src/EShopOnAbp.WebPublicGateway/appsettings.Development.json b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/appsettings.Development.json new file mode 100644 index 00000000..8983e0fc --- /dev/null +++ b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/gateways/web-public/src/EShopOnAbp.WebPublicGateway/appsettings.json b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/appsettings.json new file mode 100644 index 00000000..4d945a08 --- /dev/null +++ b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/appsettings.json @@ -0,0 +1,55 @@ +{ + "App": { + "SelfUrl": "https://localhost:44373", + "CorsOrigins": "https://localhost:44335" + }, + "AuthServer": { + "Authority": "https://localhost:44330", + "RequireHttpsMetadata": "true", + "SwaggerClientId": "WebPublicGateway_Swagger", + "SwaggerClientSecret": "1q2w3e*" + }, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*", + "Routes": [ + { + "DownstreamPathTemplate": "/api/account/{everything}", + "DownstreamScheme": "https", + "DownstreamHostAndPorts": [ + { + "Host": "localhost", + "Port": 44351 + } + ], + "UpstreamPathTemplate": "/api/account/{everything}", + "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] + }, + { + "DownstreamPathTemplate": "/api/abp/{everything}", + "DownstreamScheme": "https", + "DownstreamHostAndPorts": [ + { + "Host": "localhost", + "Port": 44353 + } + ], + "UpstreamPathTemplate": "/api/abp/{everything}", + "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] + } + ], + "GlobalConfiguration": { + "BaseUrl": "https://localhost:44373" + }, + "Redis": { + "Configuration": "localhost:6379" + }, + "ElasticSearch": { + "Url": "http://localhost:9200" + } +} diff --git a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs index 864e8591..bfcc3cd9 100644 --- a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs +++ b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs @@ -95,7 +95,7 @@ namespace EShopOnAbp.IdentityService.DbMigrations new[] { "IdentityService", "AdministrationService", "SaasService" }); await CreateSwaggerClientAsync("WebGateway", new[] { "IdentityService", "AdministrationService", "SaasService" }); - await CreateSwaggerClientAsync("PublicWebGateway", new[] { "" }); + await CreateSwaggerClientAsync("WebPublicGateway" ); } private async Task CreateSwaggerClientAsync(string name, string[] scopes = null) diff --git a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/appsettings.json b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/appsettings.json index d39a076b..0f39f591 100644 --- a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/appsettings.json +++ b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/appsettings.json @@ -52,8 +52,8 @@ "WebGateway": { "RootUrl": "https://localhost:44372" }, - "PublicWebGateway": { - "RootUrl": "https://localhost:44353" + "WebPublicGateway": { + "RootUrl": "https://localhost:44373" } } }