Skip to content

Commit

Permalink
Apply port selection logic to manifest publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
ReubenBond committed Apr 4, 2024
1 parent e7f62f3 commit 09f5ae9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Aspire.Hosting/Publishing/ManifestPublishingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,17 @@ public void WriteBindings(IResource resource)
Writer.WriteString("protocol", endpoint.Protocol.ToString().ToLowerInvariant());
Writer.WriteString("transport", endpoint.Transport);

int? targetPort = (resource, endpoint.UriScheme, endpoint.TargetPort) switch
int? targetPort = (resource, endpoint.UriScheme, endpoint.TargetPort, endpoint.Port) switch
{
// The port was specified so use it
(_, _, int port) => port,
(_, _, int target, _) => target,

// Project resources get their default port from the deployment tool
// Container resources get their default listening port from the exposed port.
(ContainerResource, _, _, int port) => port,

// Project resources get their default listening port from the deployment tool
// ideally we would default to a known port but we don't know it at this point
(ProjectResource, var scheme, null) when scheme is "http" or "https" => null,
(ProjectResource, var scheme, null, _) when scheme is "http" or "https" => null,

// Allocate a dynamic port
_ => PortAllocator.AllocatePort()
Expand Down

0 comments on commit 09f5ae9

Please sign in to comment.