Skip to content

Commit

Permalink
Bugfix/fix docker ports (#316)
Browse files Browse the repository at this point in the history
* update ports

* fix settings for docker

* update port settings

* Fix Default Port setting
  • Loading branch information
Freezor authored Jun 28, 2024
1 parent 81f16da commit ab15ab4
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/AasxServerBlazor/BlazorServerStarter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public static class BlazorServerStarter
{
private const string AppSettingsFileName = "appsettings.json";
private const string KestrelEndpointsHttpUrl = "Kestrel:Endpoints:Http:Url";
private const string DefaultUrl = "http://+:5001";
private const string DefaultPort = "5001";
private const string DefaultUrl = $"http://*:{DefaultPort}";
private const char KestrelUrlSeparator = ':';

public static void Main(string[] args)
Expand Down Expand Up @@ -45,17 +46,23 @@ private static IHost BuildHost(string[] args, IConfiguration config)
private static IHostBuilder CreateHostBuilder(string[] args, IConfiguration config)
{
var url = config[KestrelEndpointsHttpUrl]?.Split(KestrelUrlSeparator);
if (url?[2] != null)
if (url?.Length > 2 && int.TryParse(url[2], out var port))
{
Program.blazorPort = url[2];
// Use the dynamically retrieved port
Program.blazorPort = port.ToString();
}

else
{
// Use default port if dynamic port retrieval fails
Program.blazorPort = DefaultPort;
}

Check notice

Code scanning / CodeQL

Missed ternary opportunity Note

Both branches of this 'if' statement write to the same variable - consider using '?' to express intent better.

return Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder
.UseStartup<Startup>()
.UseUrls(DefaultUrl);
.UseUrls(DefaultUrl)
.UseStartup<Startup>();
});
}

Expand Down

0 comments on commit ab15ab4

Please sign in to comment.