f20a4b49ff
- gateway/Dockerfile gains a `landing` target: caddy:2-alpine + the shared Vite build (identical build args keep the ui stage a single cached build); the gateway target drops landing.html from the embed. - The contour caddy routes /app/, /telegram/ and the Connect path to the gateway; the catch-all — the landing at / and any stray path — goes to the new landing service, so junk traffic is absorbed by static file serving. - deploy/landing/Caddyfile mirrors the webui caching (immutable assets, no-cache shells) and falls back unknown paths to the landing shell. - The gateway's / now 308-redirects to /app/ (keeps a local no-caddy run usable); webui placeholder landing.html removed. - CI deploy probe checks both / (landing) and /app/ (gateway). Verified: both images build; the landing container serves landing.html at / (no-cache) with junk-path fallback; the gateway image redirects / to /app/ and carries no landing content.
58 lines
2.1 KiB
Go
58 lines
2.1 KiB
Go
package webui
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// get drives the handler with a GET for the given path and returns the response.
|
|
func get(t *testing.T, h http.Handler, target string) *http.Response {
|
|
t.Helper()
|
|
rec := httptest.NewRecorder()
|
|
h.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, target, nil))
|
|
return rec.Result()
|
|
}
|
|
|
|
func body(t *testing.T, resp *http.Response) string {
|
|
t.Helper()
|
|
b, _ := io.ReadAll(resp.Body)
|
|
return string(b)
|
|
}
|
|
|
|
// TestShellNoCache: the served HTML shell carries no-cache so a new deploy's
|
|
// shell (and the asset URLs it references) is fetched fresh.
|
|
func TestShellNoCache(t *testing.T) {
|
|
h := Handler("/app/", "index.html")
|
|
if cc := get(t, h, "/app/").Header.Get("Cache-Control"); cc != "no-cache" {
|
|
t.Errorf("shell Cache-Control = %q, want no-cache", cc)
|
|
}
|
|
}
|
|
|
|
// TestAppMountServesShellStripsPrefixAndCachesAssets: "/app/" and "/telegram/" serve the app
|
|
// shell (index.html), strip their prefix, fall back for deep links, and mark hash-named
|
|
// assets immutable.
|
|
func TestAppMountServesShellStripsPrefixAndCachesAssets(t *testing.T) {
|
|
for _, prefix := range []string{"/app/", "/telegram/"} {
|
|
h := Handler(prefix, "index.html")
|
|
|
|
if resp := get(t, h, prefix); resp.StatusCode != http.StatusOK || !strings.Contains(body(t, resp), "scrabble-app-shell") {
|
|
t.Fatalf("GET %s did not serve the app shell (status %d)", prefix, resp.StatusCode)
|
|
}
|
|
// A deep link falls back to the shell so the hash router can take over.
|
|
if resp := get(t, h, prefix+"game/abc"); resp.StatusCode != http.StatusOK || !strings.Contains(body(t, resp), "scrabble-app-shell") {
|
|
t.Fatalf("GET %sgame/abc did not fall back to the app shell (status %d)", prefix, resp.StatusCode)
|
|
}
|
|
// A hash-named asset is served directly and marked immutable.
|
|
resp := get(t, h, prefix+"assets/.gitkeep")
|
|
if resp.StatusCode != http.StatusOK {
|
|
t.Fatalf("GET %sassets/.gitkeep status = %d, want 200", prefix, resp.StatusCode)
|
|
}
|
|
if cc := resp.Header.Get("Cache-Control"); !strings.Contains(cc, "immutable") {
|
|
t.Errorf("asset Cache-Control = %q, want immutable", cc)
|
|
}
|
|
}
|
|
}
|