From ccb2e9548e368ded780633c97e6d7d4342f62c5c Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Sun, 30 Jan 2022 02:01:29 +0300 Subject: [PATCH] moved Kestrel configuration to appsettings --- .../Program.cs | 44 +------------------ .../appsettings.json | 12 +++++ .../ApplicationBuilderHelper.cs | 7 --- 3 files changed, 13 insertions(+), 50 deletions(-) diff --git a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Program.cs b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Program.cs index 38392d36..3ae318fc 100644 --- a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Program.cs +++ b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/Program.cs @@ -2,10 +2,6 @@ using System.Threading.Tasks; using EShopOnAbp.Shared.Hosting.AspNetCore; using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Server.Kestrel.Core; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; using Serilog; namespace EShopOnAbp.CatalogService; @@ -22,29 +18,7 @@ public class Program { Log.Information($"Starting {assemblyName}."); - var builder = WebApplication.CreateBuilder(args); - builder.WebHost.ConfigureKestrel(serverOptions => - { - serverOptions.ConfigureEndpointDefaults(listenOptions => - { - listenOptions.Protocols = HttpProtocols.Http1AndHttp2; - }); - serverOptions.ListenLocalhost(44354, opts => - { - opts.UseHttps(); - opts.Protocols = HttpProtocols.Http1AndHttp2; - }); - // Grpc port - serverOptions.ListenLocalhost(81, opts => { opts.Protocols = HttpProtocols.Http2; }); - }); - builder.Host - .AddAppSettingsSecretsJson() - .UseAutofac() - .UseSerilog(); - - await builder.AddApplicationAsync(); - var app = builder.Build(); - + var app = await ApplicationBuilderHelper.BuildApplicationAsync(args); await app.InitializeApplicationAsync(); await app.RunAsync(); @@ -60,20 +34,4 @@ public class Program Log.CloseAndFlush(); } } - - // static (int httpPort, int grpcPort) GetDefinedPorts(IConfiguration config) - // { - // var grpcPort = config.GetValue("GRPC_PORT", 81); - // var port = config.GetValue("PORT", 80); - // return (port, grpcPort); - // } - // - // static IConfiguration GetConfiguration() - // { - // return new ConfigurationBuilder() - // .SetBasePath(Directory.GetCurrentDirectory()) - // .AddJsonFile("appsettings.json") - // .AddEnvironmentVariables() - // .Build(); - // } } \ No newline at end of file diff --git a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/appsettings.json b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/appsettings.json index 7b5799db..5d2eda53 100644 --- a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/appsettings.json +++ b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/appsettings.json @@ -40,5 +40,17 @@ }, "ElasticSearch": { "Url": "http://localhost:9200" + }, + "Kestrel": { + "Endpoints": { + "Http": { + "Url": "https://localhost:44354", + "Protocols": "Http1AndHttp2" + }, + "gRPC": { + "Url": "http://localhost:81", + "Protocols": "Http2" + } + } } } diff --git a/shared/EShopOnAbp.Shared.Hosting.AspNetCore/ApplicationBuilderHelper.cs b/shared/EShopOnAbp.Shared.Hosting.AspNetCore/ApplicationBuilderHelper.cs index 25cdd1f4..15a9bd5e 100644 --- a/shared/EShopOnAbp.Shared.Hosting.AspNetCore/ApplicationBuilderHelper.cs +++ b/shared/EShopOnAbp.Shared.Hosting.AspNetCore/ApplicationBuilderHelper.cs @@ -15,13 +15,6 @@ public static class ApplicationBuilderHelper where TStartupModule : IAbpModule { var builder = WebApplication.CreateBuilder(args); - builder.WebHost.ConfigureKestrel(serverOptions => - { - serverOptions.ConfigureEndpointDefaults(listenOptions => - { - listenOptions.Protocols = HttpProtocols.Http1AndHttp2; - }); - }); builder.Host .AddAppSettingsSecretsJson() .UseAutofac()