From 8afc25766fba3405b2e22231caf9bbc25204fee4 Mon Sep 17 00:00:00 2001 From: Christopher LaPointe Date: Sun, 21 May 2023 10:21:00 -0400 Subject: [PATCH] Use loading template, correctly wait for load --- assets/splash.html | 32 +++++++++++++++----------------- main.go | 21 ++++++++++++++++++--- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/assets/splash.html b/assets/splash.html index 5cf8fc5..03708a5 100644 --- a/assets/splash.html +++ b/assets/splash.html @@ -4,13 +4,13 @@ - + Loading...
-

Booting Application

+

Loading {{.Name}}

@@ -26,22 +26,20 @@
\ No newline at end of file diff --git a/main.go b/main.go index 4e7ce23..066aa3c 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( _ "embed" "encoding/json" "errors" + "html/template" "io" "io/fs" "net/http" @@ -25,6 +26,14 @@ var httpAssets embed.FS const httpAssetPrefix = "/__llassets/" +type SplashModel struct { + Name string + WaitForCode int + WaitForPath string +} + +var splashTemplate = template.Must(template.ParseFS(httpAssets, "assets/splash.html")) + var dockerClient *client.Client type containerState struct { @@ -157,11 +166,17 @@ func ContainerHandler(w http.ResponseWriter, r *http.Request) { } ct, _ := findContainerByHostname(r.Context(), host) - if ct != nil { + if ct != nil || true { // TODO: Send response before querying anything about the container (the slow bit) - splash, _ := httpAssets.Open(path.Join("assets", Config.Splash)) w.WriteHeader(http.StatusAccepted) - io.Copy(w, splash) + renderErr := splashTemplate.Execute(w, SplashModel{ + Name: host, + WaitForCode: 200, // TODO Config-based + WaitForPath: "/", + }) + if renderErr != nil { + logrus.Error(renderErr) + } // Look to start the container state := getOrCreateState(ct.ID)