s3browser-backend/internal/httpserver/staticFiles.go
2021-09-24 15:39:23 +02:00

33 lines
572 B
Go

//go:build prod
// +build prod
package httpserver
import (
"embed"
"io/fs"
"net/http"
"os"
)
// content holds our static web server content.
//go:embed static
var staticFiles embed.FS
type spaFileSystem struct {
root http.FileSystem
}
func (spa *spaFileSystem) Open(name string) (http.File, error) {
f, err := spa.root.Open(name)
if os.IsNotExist(err) {
return spa.root.Open("index.html")
}
return f, err
}
func initStatic(e *mux.Router) {
staticFS, _ := fs.Sub(staticFiles, "static")
r.Handle("/", http.FileServer(&spaFileSystem{http.FS(staticFS)}))
}