feat: migrations
This commit is contained in:
@ -1,17 +1,23 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
|
||||
"github.com/spotdemo4/trevstack/server/internal/interceptors"
|
||||
)
|
||||
|
||||
var embedfs *http.FileSystem
|
||||
|
||||
func NewClientHandler(key string) http.Handler {
|
||||
if embedfs != nil {
|
||||
return interceptors.WithAuthRedirect(http.FileServer(*embedfs), key)
|
||||
func NewClientHandler(key string, clientFS *embed.FS) http.Handler {
|
||||
if clientFS == nil {
|
||||
return http.NotFoundHandler()
|
||||
}
|
||||
|
||||
return http.NotFoundHandler()
|
||||
client, err := fs.Sub(clientFS, "client")
|
||||
if err != nil {
|
||||
return http.NotFoundHandler()
|
||||
}
|
||||
|
||||
fs := http.FS(client)
|
||||
return interceptors.WithAuthRedirect(http.FileServer(fs), key)
|
||||
}
|
||||
|
@ -1,24 +0,0 @@
|
||||
//go:build !dev
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
//go:embed all:client
|
||||
var eclient embed.FS
|
||||
|
||||
func init() {
|
||||
log.Println("Initializing client for production")
|
||||
client, err := fs.Sub(eclient, "client")
|
||||
if err != nil {
|
||||
log.Fatalf("failed to get client: %v", err)
|
||||
}
|
||||
|
||||
fs := http.FS(client)
|
||||
embedfs = &fs
|
||||
}
|
Reference in New Issue
Block a user