aboutsummaryrefslogtreecommitdiff
path: root/backend/internal/static
diff options
context:
space:
mode:
Diffstat (limited to 'backend/internal/static')
-rw-r--r--backend/internal/static/static.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/backend/internal/static/static.go b/backend/internal/static/static.go
new file mode 100644
index 0000000..53523a3
--- /dev/null
+++ b/backend/internal/static/static.go
@@ -0,0 +1,43 @@
+package static
+
+import (
+ "embed"
+ "io/fs"
+ "log"
+ "os"
+ "path/filepath"
+)
+
+//go:embed build
+var embeddedBuild embed.FS
+
+func BuildFS() fs.FS {
+ sub, err := fs.Sub(embeddedBuild, "build")
+ if err != nil {
+ log.Printf("[static] embed nao disponivel, tentando filesystem: %v", err)
+ // Fallback: look for build directory relative to the backend binary
+ dir := os.Getenv("YAUM_STATIC_DIR")
+ if dir == "" {
+ // Try common locations
+ candidates := []string{
+ "../frontend/build",
+ "frontend/build",
+ "./build",
+ }
+ for _, c := range candidates {
+ if info, e := os.Stat(c); e == nil && info.IsDir() {
+ dir = c
+ break
+ }
+ }
+ }
+ if dir != "" {
+ abs, _ := filepath.Abs(dir)
+ log.Printf("[static] servindo de %s", abs)
+ return os.DirFS(dir)
+ }
+ return nil
+ }
+ log.Println("[static] servindo de embed")
+ return sub
+}