Skip to content

Commit

Permalink
[release/8.0-preview2] Inject the https port for the redirect middlew…
Browse files Browse the repository at this point in the history
…are (#1467)

* Inject the https port for the redirect middleware

* Oops

---------

Co-authored-by: David Fowler <[email protected]>
  • Loading branch information
github-actions[bot] and davidfowl authored Dec 19, 2023
1 parent ed80c0b commit 17dd83f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Aspire.Hosting/Dcp/ApplicationExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ private static void ApplyLaunchProfile(AppResource executableResource, Dictionar

private static void InjectPortEnvVars(AppResource executableResource, Dictionary<string, string> config)
{
ServiceAppResource? httpsServiceAppResource = null;
// Inject environment variables for services produced by this executable.
foreach (var serviceProduced in executableResource.ServicesProduced)
{
Expand All @@ -493,6 +494,23 @@ private static void InjectPortEnvVars(AppResource executableResource, Dictionary
{
config.Add(envVar, $"{{{{- portForServing \"{name}\" }}}}");
}

if (httpsServiceAppResource is null && serviceProduced.ServiceBindingAnnotation.UriScheme == "https")
{
httpsServiceAppResource = serviceProduced;
}
}

// REVIEW: If you run as an executable, we don't know that you're an ASP.NET Core application so we don't want to
// inject ASPNETCORE_HTTPS_PORT.
if (executableResource.ModelResource is ProjectResource)
{
// Add the environment variable for the HTTPS port if we have an HTTPS service. This will make sure the
// HTTPS redirection middleware avoids redirecting to the internal port.
if (httpsServiceAppResource is not null)
{
config.Add("ASPNETCORE_HTTPS_PORT", $"{{{{- portFor \"{httpsServiceAppResource.Service.Metadata.Name}\" }}}}");
}
}
}

Expand Down

0 comments on commit 17dd83f

Please sign in to comment.