Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround for frontend-version page not working in podman v5 #105

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 29 additions & 22 deletions src/Services/LocalFrontend/Implementation/LocalFrontendService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,52 @@
using LocalTest.Models;
using LocalTest.Services.LocalFrontend.Interface;
using Microsoft.Extensions.Options;
using static System.Linq.Enumerable;

namespace LocalTest.Services.LocalFrontend;

public class LocalFrontendService: ILocalFrontendService
public class LocalFrontendService : ILocalFrontendService
{
private readonly HttpClient _httpClient;
private static readonly Range PortRange = 8080..8090;
private readonly string _localFrontedBaseUrl;

public LocalFrontendService(IHttpClientFactory httpClientFactory, IOptions<LocalPlatformSettings> localPlatformSettings)
public LocalFrontendService(
IHttpClientFactory httpClientFactory,
IOptions<LocalPlatformSettings> localPlatformSettings
)
{
_httpClient = httpClientFactory.CreateClient();
_localFrontedBaseUrl = $"{localPlatformSettings.Value.LocalFrontendProtocol}://{localPlatformSettings.Value.LocalFrontendHostname}";
_httpClient.Timeout = TimeSpan.FromMilliseconds(500);
_localFrontedBaseUrl =
$"{localPlatformSettings.Value.LocalFrontendProtocol}://{localPlatformSettings.Value.LocalFrontendHostname}";
}

public async Task<List<LocalFrontendInfo>> GetLocalFrontendDevPorts()
{
var ports = new List<LocalFrontendInfo>();
for (int i = PortRange.Start.Value; i < PortRange.End.Value; i++)
var tasks = Range(PortRange.Start.Value, PortRange.End.Value).Select(port => TestFrontendDevPort(port));
var result = await Task.WhenAll(tasks);
return result.Where(x => x != null).Select(x => x!.Value).ToList();
}

private async Task<LocalFrontendInfo?> TestFrontendDevPort(int port)
{
try
{
try
var response = await _httpClient.GetAsync($"{_localFrontedBaseUrl}:{port.ToString()}/");
if (response.Headers.TryGetValues("X-Altinn-Frontend-Branch", out var values))
{
var response =
await _httpClient.GetAsync($"{_localFrontedBaseUrl}:{i.ToString()}/");
if (response.Headers.TryGetValues("X-Altinn-Frontend-Branch", out var values))
return new LocalFrontendInfo()
{

ports.Add(new LocalFrontendInfo()
{
Port = i.ToString(),
Branch = values?.First() ?? "Unknown"
});
}
}
catch(HttpRequestException)
{

Port = port.ToString(),
Branch = values?.First() ?? "Unknown"
};
}
}
return ports;
catch (TaskCanceledException) { }
catch (HttpRequestException) { }

return null;
}
}
}

Loading