initial commit

This commit is contained in:
Семен Каменецкий
2026-09-15 15:31:54 +03:00
parent 702f108aff
commit 09dd1f7217
65 changed files with 4640 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
package static
import (
"embed"
"io"
"io/fs"
"log"
"net/http"
"strings"
)
//go:embed app/dist
var appFS embed.FS
var Handler = func() http.HandlerFunc {
distFS, err := fs.Sub(appFS, "app/dist")
if err != nil {
log.Fatalln(err)
}
fileServer := http.FileServer(http.FS(distFS))
return func(w http.ResponseWriter, r *http.Request) {
path := strings.TrimPrefix(r.URL.Path, "/")
_, err := distFS.Open(path)
if err == nil || path == "" {
fileServer.ServeHTTP(w, r)
return
}
indexFile, err := distFS.Open("index.html")
if err != nil {
http.Error(w, "frontend build not found", http.StatusInternalServerError)
return
}
defer func() { _ = indexFile.Close() }()
stat, _ := indexFile.Stat()
http.ServeContent(w, r, "index.html", stat.ModTime(), indexFile.(io.ReadSeeker))
}
}()