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

Exposes proxy port in UI #251

Merged
merged 2 commits into from Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions Hippo/Program.cs
@@ -1,6 +1,7 @@

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Threading.Tasks;
using Hippo.Config;
Expand All @@ -20,6 +21,8 @@ public static class Program
{
// TODO get value from configuration.
public static string JobScheduler => Environment.GetEnvironmentVariable("HIPPO_JOB_SCHEDULER")?.ToUpperInvariant() ?? default;
private static string proxyPort = string.Empty;
public static string ProxyPort => Program.proxyPort;

public static void Main(string[] args)
{
Expand All @@ -43,11 +46,29 @@ public static void Main(string[] args)
var proxyUpdateTaskQueue = hippoHost.Services.GetRequiredService<ITaskQueue<ReverseProxyUpdateRequest>>();
var proxyHostBuilder = CreateProxyHostBuilder(proxyUpdateTaskQueue);
var proxyHost = proxyHostBuilder.Build();
proxyPort = GetProxyHTTPSPort(proxyHost.Services.GetRequiredService<IConfiguration>());
tasks.Add(hippoHost.RunAsync());
tasks.Add(proxyHost.RunAsync());
Task.WaitAny(tasks.ToArray());
}

/// <summary>
/// Gets the HTTPS Proxy port so that links can be created correctly in the Hippo UI. this will need to be updated for external schedulers.
/// </summary>
/// <param name="config">The Proxy Configuration</param>
/// <returns>The proy HTTPS Port as a string</returns>

static string GetProxyHTTPSPort(IConfiguration config)
{
var port = string.Empty;
var proxyUrl = config?.GetValue<string>("Kestrel:Endpoints:Https:Url");
if (!string.IsNullOrEmpty(proxyUrl) && Uri.TryCreate(proxyUrl, UriKind.Absolute, out Uri result))
{
port = result.Port == 0 || result.Port == 443 ? "443" : result.Port.ToString(CultureInfo.InvariantCulture);
}
return port;
}

// This has to be called CreateHostBuilder because the ef migrations tool looks specifically
// for that method name.
// NOTE do not run the ef migrations tool with env var HIPPO_JOB_SCHEDULER set to WAGI-DOTNET as it will fail.
Expand Down
2 changes: 1 addition & 1 deletion Hippo/Views/Shared/_NavSidebar.cshtml
Expand Up @@ -43,7 +43,7 @@
@Html.DisplayFor(modelItem => item.Name)
</p>
</a>
<a class="env-url" target="_blank" href="https://@item.Domain.Name">
<a class="env-url" target="_blank" href="https://@item.Domain.Name:@Hippo.Program.ProxyPort">
simongdavies marked this conversation as resolved.
Show resolved Hide resolved
@Html.DisplayFor(modelItem => item.Domain.Name) <i class="fa fa-external-link"></i>
</a>

Expand Down