Skip to content

Commit

Permalink
Merge pull request #251 from simongdavies/show-proxy-port
Browse files Browse the repository at this point in the history
Exposes proxy port in UI
  • Loading branch information
simongdavies committed Sep 14, 2021
2 parents 301db23 + 808629b commit b05d33f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
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 ? string.Empty : $":{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">
@Html.DisplayFor(modelItem => item.Domain.Name) <i class="fa fa-external-link"></i>
</a>

Expand Down

0 comments on commit b05d33f

Please sign in to comment.