Skip to content

Commit 2268a5e

Browse files
committed
Add code to wait for Angular to start
1 parent aacce9a commit 2268a5e

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

MyApp/Program.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@
7373
if (app.Environment.IsDevelopment())
7474
{
7575
// Start the Angular dev server if it's not running
76-
var portAvailable = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties()
77-
.GetActiveTcpListeners().All(x => x.Port != 4200);
78-
if (portAvailable && nodeProxy.TryStartNode("../MyApp.Client", out var process))
76+
bool IsPortAvailable(int port) => System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties()
77+
.GetActiveTcpListeners().All(x => x.Port != port);
78+
if (IsPortAvailable(4200) && nodeProxy.TryStartNode("../MyApp.Client", out var process))
7979
{
8080
app.Lifetime.ApplicationStopping.Register(() => {
8181
if (!process.HasExited)
@@ -89,7 +89,16 @@
8989
app.UseWebSockets();
9090
app.MapViteHmr(nodeProxy);
9191
app.MapFallbackToNode(nodeProxy);
92-
Thread.Sleep(200); // Wait for Node to start
92+
93+
// Wait for Angular dev server to start
94+
var timeout = TimeSpan.FromSeconds(30);
95+
var started = DateTime.UtcNow;
96+
while (DateTime.UtcNow - started < timeout)
97+
{
98+
if (IsPortAvailable(4200))
99+
break;
100+
Thread.Sleep(100);
101+
}
93102
}
94103
else
95104
{

0 commit comments

Comments
 (0)