blob: 53523a3a7d1329f86f10e07e450a9b49a6ecca5f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
}
|