mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 04:18:01 +00:00
5e931a3c13
* fix: serve console env from os (not statik) * ZITADEL_CONSOLE_ENV_PATH for (local) overwrite possibility * name EnvOverwritePath * fix: console env directory * fix mount path * fix default dir
50 lines
1011 B
Go
50 lines
1011 B
Go
package console
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"os"
|
|
"path"
|
|
|
|
"github.com/rakyll/statik/fs"
|
|
|
|
_ "github.com/caos/zitadel/pkg/console/statik"
|
|
)
|
|
|
|
type Config struct {
|
|
Port string
|
|
EnvOverwriteDir string
|
|
}
|
|
|
|
type spaHandler struct {
|
|
fileSystem http.FileSystem
|
|
}
|
|
|
|
const (
|
|
envRequestPath = "/assets/environment.json"
|
|
envDefaultDir = "/console/"
|
|
)
|
|
|
|
func (i *spaHandler) Open(name string) (http.File, error) {
|
|
ret, err := i.fileSystem.Open(name)
|
|
if !os.IsNotExist(err) || path.Ext(name) != "" {
|
|
return ret, err
|
|
}
|
|
|
|
return i.fileSystem.Open("/index.html")
|
|
}
|
|
|
|
func Start(ctx context.Context, config Config) error {
|
|
statikFS, err := fs.NewWithNamespace("console")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
envDir := envDefaultDir
|
|
if config.EnvOverwriteDir != "" {
|
|
envDir = config.EnvOverwriteDir
|
|
}
|
|
http.Handle("/", http.FileServer(&spaHandler{statikFS}))
|
|
http.Handle(envRequestPath, http.StripPrefix("/assets", http.FileServer(http.Dir(envDir))))
|
|
return http.ListenAndServe(":"+config.Port, nil)
|
|
}
|