fix: conditional client build
This commit is contained in:
@ -1,19 +0,0 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/spotdemo4/trevstack/server/internal/interceptors"
|
||||
)
|
||||
|
||||
func NewClientHandler(client embed.FS, key string) http.Handler {
|
||||
clientFs, err := fs.Sub(client, "client")
|
||||
if err != nil {
|
||||
log.Fatalf("failed to get sub filesystem: %v", err)
|
||||
}
|
||||
|
||||
return interceptors.WithAuthRedirect(http.FileServer(http.FS(clientFs)), key)
|
||||
}
|
17
server/internal/handlers/client/client.go
Normal file
17
server/internal/handlers/client/client.go
Normal file
@ -0,0 +1,17 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"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)
|
||||
}
|
||||
|
||||
return http.NotFoundHandler()
|
||||
}
|
16
server/internal/handlers/client/client_prod.go
Normal file
16
server/internal/handlers/client/client_prod.go
Normal file
@ -0,0 +1,16 @@
|
||||
// go:build !dev
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
//go:embed client
|
||||
var eclient embed.FS
|
||||
|
||||
func init() {
|
||||
fs := http.FS(eclient)
|
||||
embedfs = &fs
|
||||
}
|
Reference in New Issue
Block a user