From da4bec8a99c490c01652519111eb7a5cc6e4f3f5 Mon Sep 17 00:00:00 2001 From: raix <1136718+raix@users.noreply.github.com> Date: Sat, 25 Nov 2023 14:51:49 +0100 Subject: [PATCH] Wait for WebApp build to be ready in development mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Thomas Jespersen Signed-off-by: Morten N.O. Nørgaard Henriksen <1136718+raix@users.noreply.github.com> --- .../ApiCore/Middleware/WebAppMiddleware.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/application/shared-kernel/ApiCore/Middleware/WebAppMiddleware.cs b/application/shared-kernel/ApiCore/Middleware/WebAppMiddleware.cs index eb6788b99..a0ee07e90 100644 --- a/application/shared-kernel/ApiCore/Middleware/WebAppMiddleware.cs +++ b/application/shared-kernel/ApiCore/Middleware/WebAppMiddleware.cs @@ -142,8 +142,18 @@ public static IApplicationBuilder UseWebAppMiddleware( var buildRootPath = GetWebAppDistRoot(webAppProjectName, "dist"); var templateFilePath = Path.Combine(buildRootPath, "index.html"); - if (!File.Exists(templateFilePath) && - Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") != "development") + if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "development") + { + var tryUntil = DateTime.UtcNow.AddSeconds(10); + while (!File.Exists(templateFilePath)) + { + if (DateTime.UtcNow > tryUntil) break; + Debug.WriteLine($"Waiting for {webAppProjectName} build to be ready..."); + Thread.Sleep(TimeSpan.FromSeconds(1)); + } + } + + if (!File.Exists(templateFilePath)) { throw new FileNotFoundException("index.html does not exist.", templateFilePath); }