@@ -21,8 +21,8 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels
2121 /// <seealso cref="Microsoft.AspNetCore.NodeServices.HostingModels.OutOfProcessNodeInstance" />
2222 internal class HttpNodeInstance : OutOfProcessNodeInstance
2323 {
24- private static readonly Regex PortMessageRegex =
25- new Regex ( @"^\[Microsoft.AspNetCore.NodeServices.HttpNodeHost:Listening on port (\d+)\]$" ) ;
24+ private static readonly Regex EndpointMessageRegex =
25+ new Regex ( @"^\[Microsoft.AspNetCore.NodeServices.HttpNodeHost:Listening on {(.*?)} port (\d+)\]$" ) ;
2626
2727 private static readonly JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings
2828 {
@@ -32,7 +32,7 @@ internal class HttpNodeInstance : OutOfProcessNodeInstance
3232
3333 private readonly HttpClient _client ;
3434 private bool _disposed ;
35- private int _portNumber ;
35+ private string _endpoint ;
3636
3737 public HttpNodeInstance ( NodeServicesOptions options , int port = 0 )
3838 : base (
@@ -63,7 +63,7 @@ protected override async Task<T> InvokeExportAsync<T>(
6363 {
6464 var payloadJson = JsonConvert . SerializeObject ( invocationInfo , jsonSerializerSettings ) ;
6565 var payload = new StringContent ( payloadJson , Encoding . UTF8 , "application/json" ) ;
66- var response = await _client . PostAsync ( "http://localhost:" + _portNumber , payload , cancellationToken ) ;
66+ var response = await _client . PostAsync ( _endpoint , payload , cancellationToken ) ;
6767
6868 if ( ! response . IsSuccessStatusCode )
6969 {
@@ -111,13 +111,19 @@ protected override async Task<T> InvokeExportAsync<T>(
111111
112112 protected override void OnOutputDataReceived ( string outputData )
113113 {
114- // Watch for "port selected" messages, and when observed, store the port number
114+ // Watch for "port selected" messages, and when observed,
115+ // store the IP (IPv4/IPv6) and port number
115116 // so we can use it when making HTTP requests. The child process will always send
116117 // one of these messages before it sends a "ready for connections" message.
117- var match = _portNumber != 0 ? null : PortMessageRegex . Match ( outputData ) ;
118+ var match = string . IsNullOrEmpty ( _endpoint ) ? EndpointMessageRegex . Match ( outputData ) : null ;
118119 if ( match != null && match . Success )
119120 {
120- _portNumber = int . Parse ( match . Groups [ 1 ] . Captures [ 0 ] . Value ) ;
121+ var port = int . Parse ( match . Groups [ 2 ] . Captures [ 0 ] . Value ) ;
122+ var resolvedIpAddress = match . Groups [ 1 ] . Captures [ 0 ] . Value ;
123+
124+ //IPv6 must be wrapped with [] brackets
125+ resolvedIpAddress = resolvedIpAddress == "::1" ? $ "[{ resolvedIpAddress } ]" : resolvedIpAddress ;
126+ _endpoint = $ "http://{ resolvedIpAddress } :{ port } ";
121127 }
122128 else
123129 {
0 commit comments