Refactor Kestrel configuration to support dynamic port assignment and update appsettings for HTTP endpoint
This commit is contained in:
@@ -22,10 +22,16 @@ namespace ResourceMonitorService
|
|||||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
{
|
{
|
||||||
var builder = WebApplication.CreateBuilder();
|
var builder = WebApplication.CreateBuilder();
|
||||||
builder.WebHost.ConfigureKestrel(options =>
|
/* builder.WebHost.ConfigureKestrel(options =>
|
||||||
{
|
{
|
||||||
options.ListenAnyIP(5000); // Replace 5000 with your desired port
|
options.ListenAnyIP(5000); // Replace 5000 with your desired port
|
||||||
});
|
}); */
|
||||||
|
/* builder.WebHost.ConfigureKestrel(options =>
|
||||||
|
{
|
||||||
|
var url = builder.Configuration.GetValue<string>("Kestrel:Endpoints:Http:Url");
|
||||||
|
var port = url.Split(':').Last();
|
||||||
|
options.ListenAnyIP(int.Parse(port));
|
||||||
|
}); */
|
||||||
builder.Services.AddCors(options =>
|
builder.Services.AddCors(options =>
|
||||||
{
|
{
|
||||||
options.AddPolicy("AllowAllOrigins",
|
options.AddPolicy("AllowAllOrigins",
|
||||||
|
|||||||
@@ -4,5 +4,13 @@
|
|||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
"Microsoft.Hosting.Lifetime": "Information"
|
"Microsoft.Hosting.Lifetime": "Information"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"RunAsWindowsService": false,
|
||||||
|
"Kestrel": {
|
||||||
|
"Endpoints": {
|
||||||
|
"Http": {
|
||||||
|
"Url": "http://*:5000"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user