2020-05-13 14:41:43 +02:00
|
|
|
//go:generate statik -src=../../console/dist/app
|
|
|
|
|
2020-03-25 07:58:58 +01:00
|
|
|
package console
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-05-13 14:41:43 +02:00
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
|
|
|
|
"github.com/rakyll/statik/fs"
|
2020-03-25 07:58:58 +01:00
|
|
|
|
2020-05-13 14:41:43 +02:00
|
|
|
_ "github.com/caos/zitadel/pkg/console/statik"
|
2020-03-25 07:58:58 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2020-05-13 14:41:43 +02:00
|
|
|
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 {
|
2020-05-13 14:41:43 +02:00
|
|
|
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
|
|
|
}
|