fix test
This commit is contained in:
parent
0e02a037b4
commit
fc1f10cd0b
|
|
@ -33,19 +33,19 @@ func (s *Server) appHandler() http.Handler {
|
||||||
|
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
p := strings.TrimPrefix(r.URL.Path, "/")
|
p := strings.TrimPrefix(r.URL.Path, "/")
|
||||||
|
|
||||||
if file, err := fsys.Open(p); err == nil {
|
if file, err := fsys.Open(p); err == nil {
|
||||||
file.Close()
|
file.Close()
|
||||||
|
|
||||||
// Ensure proper Content-Type headers
|
// Ensure proper Content-Type headers
|
||||||
if contentType := mime.TypeByExtension(filepath.Ext(p)); contentType != "" {
|
if contentType := mime.TypeByExtension(filepath.Ext(p)); contentType != "" {
|
||||||
w.Header().Set("Content-Type", contentType)
|
w.Header().Set("Content-Type", contentType)
|
||||||
}
|
}
|
||||||
|
|
||||||
fileServer.ServeHTTP(w, r)
|
fileServer.ServeHTTP(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback – serve index.html for unknown paths so React Router works
|
// Fallback – serve index.html for unknown paths so React Router works
|
||||||
data, err := fs.ReadFile(fsys, "index.html")
|
data, err := fs.ReadFile(fsys, "index.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -56,7 +56,7 @@ func (s *Server) appHandler() http.Handler {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
http.ServeContent(w, r, "index.html", time.Time{}, bytes.NewReader(data))
|
http.ServeContent(w, r, "index.html", time.Time{}, bytes.NewReader(data))
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -15,26 +15,25 @@ func TestEmbeddedAssets(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("app/dist not found in embedded filesystem - UI not built")
|
t.Fatal("app/dist not found in embedded filesystem - UI not built")
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := fs.ReadFile(fsys, "index.html")
|
data, err := fs.ReadFile(fsys, "index.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("index.html not found - run 'go generate' first")
|
t.Fatal("index.html not found - run 'go generate' first")
|
||||||
}
|
}
|
||||||
|
|
||||||
html := string(data)
|
html := string(data)
|
||||||
|
|
||||||
if strings.Contains(html, "/src/main.tsx") {
|
if strings.Contains(html, "/src/main.tsx") {
|
||||||
t.Fatal("Wrong index.html embedded: has /src/main.tsx (dev paths). The UI was not built. Run 'npm run build' first.")
|
t.Fatal("Wrong index.html embedded: has /src/main.tsx (dev paths). The UI was not built. Run 'npm run build' first.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.Contains(html, "/assets/index-") {
|
if !strings.Contains(html, "/assets/index-") {
|
||||||
t.Fatal("Wrong index.html embedded: missing /assets/index-* (production paths). The UI was not built correctly.")
|
t.Fatal("Wrong index.html embedded: missing /assets/index-* (production paths). The UI was not built correctly.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := fsys.Open("assets"); err != nil {
|
if _, err := fsys.Open("assets"); err != nil {
|
||||||
t.Fatal("assets/ directory not found - UI build incomplete")
|
t.Fatal("assets/ directory not found - UI build incomplete")
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Log("Embedded assets verified - UI built correctly")
|
t.Log("Embedded assets verified - UI built correctly")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue