Consider React dev server ready when it starts listening, not when (and if) it compiles successfully

This commit is contained in:
Steve Sanderson
2017-11-16 09:48:38 +00:00
parent 296435e40c
commit 68c4620a55

View File

@@ -66,13 +66,16 @@ namespace Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer
sourcePath, npmScriptName, null, envVars); sourcePath, npmScriptName, null, envVars);
npmScriptRunner.AttachToLogger(logger); npmScriptRunner.AttachToLogger(logger);
Match openBrowserLine;
using (var stdErrReader = new EventedStreamStringReader(npmScriptRunner.StdErr)) using (var stdErrReader = new EventedStreamStringReader(npmScriptRunner.StdErr))
{ {
try try
{ {
openBrowserLine = await npmScriptRunner.StdOut.WaitForMatch( // Although the React dev server may eventually tell us the URL it's listening on,
new Regex("Local:\\s*(http\\S+)", RegexOptions.None, RegexMatchTimeout), // it doesn't do so until it's finished compiling, and even then only if there were
// no compiler warnings. So instead of waiting for that, consider it ready as soon
// as it starts listening for requests.
await npmScriptRunner.StdOut.WaitForMatch(
new Regex("Starting the development server", RegexOptions.None, RegexMatchTimeout),
StartupTimeout); StartupTimeout);
} }
catch (EndOfStreamException ex) catch (EndOfStreamException ex)
@@ -91,8 +94,7 @@ namespace Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer
} }
} }
var uri = new Uri(openBrowserLine.Groups[1].Value); return portNumber;
return uri.Port;
} }
} }
} }