diff --git a/apps/backend/cmd/preview/build.go b/apps/backend/cmd/preview/build.go index 8de100522d..04e51835aa 100644 --- a/apps/backend/cmd/preview/build.go +++ b/apps/backend/cmd/preview/build.go @@ -10,6 +10,7 @@ import ( "os" "os/exec" "path/filepath" + "regexp" ) // appsDir is the apps/ workspace root relative to the working directory (apps/backend/). @@ -185,6 +186,9 @@ func packageBundle(binDir, tarPath string) error { // Add Vite SPA assets. `kandev start` resolves these from /app/apps/web/dist // and passes KANDEV_WEB_DIST_DIR to the backend. webDistDir := filepath.Join(appsDir, "web", "dist") + if err := validateViteWebDist(webDistDir); err != nil { + return err + } if err := addDirToTar(tw, webDistDir, filepath.Join("app", "apps", "web", "dist")); err != nil { return fmt.Errorf("add web dist: %w", err) } @@ -201,6 +205,33 @@ func packageBundle(binDir, tarPath string) error { return gz.Close() } +func validateViteWebDist(webDistDir string) error { + indexPath := filepath.Join(webDistDir, "index.html") + indexHTML, err := os.ReadFile(indexPath) + if err != nil { + return fmt.Errorf("read web dist index: %w", err) + } + if !viteIndexHasEntrypoint(string(indexHTML)) { + return fmt.Errorf("web dist index %s is missing Vite module entrypoint", indexPath) + } + return nil +} + +var ( + scriptTagPattern = regexp.MustCompile(`(?is)