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

Inject the https port for the redirect middleware #1466

Merged
merged 2 commits into from
Dec 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Aspire.Hosting/Dcp/ApplicationExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,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 @@ -472,6 +473,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