From 5e72d299048654cdac2c86e9c224e896700fdb4e Mon Sep 17 00:00:00 2001 From: Judah Perez Date: Tue, 1 Nov 2022 19:42:11 -0700 Subject: [PATCH 1/2] combine generic host and web application --- Mmo Game Framework/MainServer/Program.cs | 42 +++++++------------ .../MainServer/Properties/launchSettings.json | 1 + 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/Mmo Game Framework/MainServer/Program.cs b/Mmo Game Framework/MainServer/Program.cs index c71cffc..ffa2fb9 100644 --- a/Mmo Game Framework/MainServer/Program.cs +++ b/Mmo Game Framework/MainServer/Program.cs @@ -31,21 +31,7 @@ static async Task Main(string[] args) //var metricServer = new KestrelMetricServer(port: 1234); //metricServer.Start(); - IHost host = Host.CreateDefaultBuilder(args) - .ConfigureLogging(builder => - { - builder.AddSimpleConsole(options => - { - options.IncludeScopes = true; - options.SingleLine = true; - options.TimestampFormat = "hh:mm:ss "; - }); - }) - .ConfigureServices(x => - { - x.AddSingleton(); - }) - .Build(); + IHost host = BuildHost(args); _logger = host.Services.GetRequiredService>(); @@ -124,8 +110,6 @@ static async Task Main(string[] args) }, false, host.Services.GetRequiredService>(), configuration); workerServer.Start(); - StartAPI(); - _logger.LogInformation("DragonGF is ready."); @@ -137,23 +121,29 @@ static async Task Main(string[] args) //metricServer.Stop(); } - private static async void StartAPI() + + + private static WebApplication BuildHost(string[] args) { - _logger.LogInformation("Starting Console API"); - // - var builder = WebApplication.CreateBuilder(); + var builder = WebApplication.CreateBuilder(args); + builder.Logging.AddSimpleConsole(options => + { + options.IncludeScopes = true; + options.SingleLine = true; + options.TimestampFormat = "hh:mm:ss "; + }); + + builder.Services.AddSingleton(); - // builder.Services.AddControllers(); var app = builder.Build(); - - // app.UseHttpsRedirection(); + + //app.UseHttpsRedirection(); app.UseAuthorization(); app.MapControllers(); - - await app.RunAsync("http://localhost:3000"); + return app; } public static MmoServer GetServer() diff --git a/Mmo Game Framework/MainServer/Properties/launchSettings.json b/Mmo Game Framework/MainServer/Properties/launchSettings.json index db10972..4cbc702 100644 --- a/Mmo Game Framework/MainServer/Properties/launchSettings.json +++ b/Mmo Game Framework/MainServer/Properties/launchSettings.json @@ -2,6 +2,7 @@ "profiles": { "MainServer": { "commandName": "Project", + "applicationUrl": "http://localhost:3000", "environmentVariables": { "DOTNET_ENVIRONMENT": "Development" //"AGONES_SDK_GRPC_HOST": "192.168.4.241" From 3cdb781eb0e8f60940778a7b7c5b3d5343940db3 Mon Sep 17 00:00:00 2001 From: Judah Perez Date: Tue, 1 Nov 2022 20:39:23 -0700 Subject: [PATCH 2/2] Specify port --- Mmo Game Framework/MainServer/Program.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Mmo Game Framework/MainServer/Program.cs b/Mmo Game Framework/MainServer/Program.cs index ffa2fb9..99d5331 100644 --- a/Mmo Game Framework/MainServer/Program.cs +++ b/Mmo Game Framework/MainServer/Program.cs @@ -16,6 +16,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; namespace MmoGameFramework { @@ -127,6 +128,7 @@ private static WebApplication BuildHost(string[] args) { var builder = WebApplication.CreateBuilder(args); + builder.WebHost.UseUrls("http://*:3000"); builder.Logging.AddSimpleConsole(options => { options.IncludeScopes = true;