Skip to content

Commit 17dd83f

Browse files
[release/8.0-preview2] Inject the https port for the redirect middleware (#1467)
* Inject the https port for the redirect middleware * Oops --------- Co-authored-by: David Fowler <[email protected]>
1 parent ed80c0b commit 17dd83f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/Aspire.Hosting/Dcp/ApplicationExecutor.cs

+18
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ private static void ApplyLaunchProfile(AppResource executableResource, Dictionar
483483

484484
private static void InjectPortEnvVars(AppResource executableResource, Dictionary<string, string> config)
485485
{
486+
ServiceAppResource? httpsServiceAppResource = null;
486487
// Inject environment variables for services produced by this executable.
487488
foreach (var serviceProduced in executableResource.ServicesProduced)
488489
{
@@ -493,6 +494,23 @@ private static void InjectPortEnvVars(AppResource executableResource, Dictionary
493494
{
494495
config.Add(envVar, $"{{{{- portForServing \"{name}\" }}}}");
495496
}
497+
498+
if (httpsServiceAppResource is null && serviceProduced.ServiceBindingAnnotation.UriScheme == "https")
499+
{
500+
httpsServiceAppResource = serviceProduced;
501+
}
502+
}
503+
504+
// 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
505+
// inject ASPNETCORE_HTTPS_PORT.
506+
if (executableResource.ModelResource is ProjectResource)
507+
{
508+
// Add the environment variable for the HTTPS port if we have an HTTPS service. This will make sure the
509+
// HTTPS redirection middleware avoids redirecting to the internal port.
510+
if (httpsServiceAppResource is not null)
511+
{
512+
config.Add("ASPNETCORE_HTTPS_PORT", $"{{{{- portFor \"{httpsServiceAppResource.Service.Metadata.Name}\" }}}}");
513+
}
496514
}
497515
}
498516

0 commit comments

Comments
 (0)