add ListenIP config option for asset server

This commit is contained in:
Robert Paciorek 2024-02-08 19:26:30 +00:00
parent 56c388b1d6
commit b7720af330
2 changed files with 7 additions and 1 deletions

View File

@ -1,6 +1,7 @@
namespace sodoff.Configuration; namespace sodoff.Configuration;
public class AssetServerConfig { public class AssetServerConfig {
public bool Enabled { get; set; } = false; public bool Enabled { get; set; } = false;
public string ListenIP { get; set; } = string.Empty;
public int Port { get; set; } = 5001; public int Port { get; set; } = 5001;
public string URLPrefix { get; set; } = string.Empty; public string URLPrefix { get; set; } = string.Empty;
public AssetServerMode Mode { get; set; } public AssetServerMode Mode { get; set; }

View File

@ -6,6 +6,7 @@ using sodoff.Model;
using sodoff.Services; using sodoff.Services;
using sodoff.Utils; using sodoff.Utils;
using System.Xml; using System.Xml;
using System.Net;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -33,10 +34,14 @@ builder.Services.AddScoped<AchievementService>();
builder.Services.AddScoped<GameDataService>(); builder.Services.AddScoped<GameDataService>();
bool assetServer = builder.Configuration.GetSection("AssetServer").GetValue<bool>("Enabled"); bool assetServer = builder.Configuration.GetSection("AssetServer").GetValue<bool>("Enabled");
string assetIP = builder.Configuration.GetSection("AssetServer").GetValue<string>("ListenIP");
int assetPort = builder.Configuration.GetSection("AssetServer").GetValue<int>("Port"); int assetPort = builder.Configuration.GetSection("AssetServer").GetValue<int>("Port");
if (assetServer) if (assetServer)
builder.Services.Configure<KestrelServerOptions>(options => { builder.Services.Configure<KestrelServerOptions>(options => {
options.ListenAnyIP(assetPort); if (String.IsNullOrEmpty(assetIP) || assetIP == "*")
options.ListenAnyIP(assetPort);
else
options.Listen(IPAddress.Parse(assetIP), assetPort);
}); });
var app = builder.Build(); var app = builder.Build();