zitadel/pkg/console/console.go

41 lines
728 B
Go
Raw Normal View History

//go:generate statik -src=../../console/dist/app
2020-03-25 07:58:58 +01:00
package console
import (
"context"
"net/http"
"os"
"path"
"github.com/rakyll/statik/fs"
2020-03-25 07:58:58 +01:00
_ "github.com/caos/zitadel/pkg/console/statik"
2020-03-25 07:58:58 +01:00
)
type Config struct {
Port string
}
type spaHandler struct {
fileSystem http.FileSystem
}
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")
2020-03-25 07:58:58 +01:00
}
2020-03-27 13:57:16 +01:00
func Start(ctx context.Context, config Config) error {
statikFS, err := fs.New()
if err != nil {
return err
}
http.Handle("/", http.FileServer(&spaHandler{statikFS}))
return http.ListenAndServe(":"+config.Port, nil)
2020-03-25 07:58:58 +01:00
}