Skip to content

Commit

Permalink
fix for warning.
Browse files Browse the repository at this point in the history
  • Loading branch information
ffMathy committed Mar 1, 2020
1 parent b3e5075 commit 6b5be4c
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/FluffySpoon.AspNet.NGrok/NGrokHostedService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ public NGrokHostedService(

public void InjectServerAddressesFeature(IServerAddressesFeature feature)
{
if (feature == null)
{
throw new ArgumentNullException(nameof(feature),
"The URL of the server could not be found - make sure it is listening on a proper hostname.");
}

_serverAddressesFeature = feature;
RunAsync();
}
Expand Down Expand Up @@ -80,14 +74,19 @@ private async Task<Tunnel[]> StartTunnelsAsync(string url)
private string AdjustApplicationHttpUrlIfNeeded()
{
var url = _options.ApplicationHttpUrl;
var addresses = _serverAddressesFeature.Addresses;

if (string.IsNullOrWhiteSpace(url) || !Uri.TryCreate(url, UriKind.Absolute, out _))
{
url = addresses.FirstOrDefault(a => a.StartsWith("http://")) ?? addresses.FirstOrDefault();
var addresses = _serverAddressesFeature?.Addresses;
if(addresses != null)
url = addresses.FirstOrDefault(a => a.StartsWith("http://")) ?? addresses.FirstOrDefault();
}

_options.ApplicationHttpUrl = url;

if (url == null)
throw new InvalidOperationException("No application URL has been set, and it could not be inferred.");

return url;
}

Expand Down

0 comments on commit 6b5be4c

Please sign in to comment.