@@ -21,8 +21,8 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels
21
21
/// <seealso cref="Microsoft.AspNetCore.NodeServices.HostingModels.OutOfProcessNodeInstance" />
22
22
internal class HttpNodeInstance : OutOfProcessNodeInstance
23
23
{
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+)\]$" ) ;
26
26
27
27
private static readonly JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings
28
28
{
@@ -32,7 +32,7 @@ internal class HttpNodeInstance : OutOfProcessNodeInstance
32
32
33
33
private readonly HttpClient _client ;
34
34
private bool _disposed ;
35
- private int _portNumber ;
35
+ private string _endpoint ;
36
36
37
37
public HttpNodeInstance ( NodeServicesOptions options , int port = 0 )
38
38
: base (
@@ -63,7 +63,7 @@ protected override async Task<T> InvokeExportAsync<T>(
63
63
{
64
64
var payloadJson = JsonConvert . SerializeObject ( invocationInfo , jsonSerializerSettings ) ;
65
65
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 ) ;
67
67
68
68
if ( ! response . IsSuccessStatusCode )
69
69
{
@@ -111,13 +111,19 @@ protected override async Task<T> InvokeExportAsync<T>(
111
111
112
112
protected override void OnOutputDataReceived ( string outputData )
113
113
{
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
115
116
// so we can use it when making HTTP requests. The child process will always send
116
117
// 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 ;
118
119
if ( match != null && match . Success )
119
120
{
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 } ";
121
127
}
122
128
else
123
129
{
0 commit comments