From a0a6bd107503b4993f6edf4e25a1e479647b71c0 Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Sun, 25 Sep 2022 14:07:47 -0400 Subject: [PATCH] Move frontend --- .gitmodules | 2 +- frontend => pkg/frontend/frontend | 0 pkg/frontend/frontend.go | 8 ++++++++ pkg/server/server.go | 8 ++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) rename frontend => pkg/frontend/frontend (100%) create mode 100644 pkg/frontend/frontend.go diff --git a/.gitmodules b/.gitmodules index 31c5452..7941c82 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "frontend"] - path = frontend + path = pkg/frontend/frontend url = https://github.com/home-assistant/frontend.git diff --git a/frontend b/pkg/frontend/frontend similarity index 100% rename from frontend rename to pkg/frontend/frontend diff --git a/pkg/frontend/frontend.go b/pkg/frontend/frontend.go new file mode 100644 index 0000000..d6b40a8 --- /dev/null +++ b/pkg/frontend/frontend.go @@ -0,0 +1,8 @@ +package frontend + +import ( + "embed" +) + +//go:embed frontend/hass_frontend +var Root embed.FS diff --git a/pkg/server/server.go b/pkg/server/server.go index 6f96dc5..0660d91 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -1,12 +1,14 @@ package server import ( + "io/fs" "log" "net/http" "sync" "dynatron.me/x/blasphem/pkg/bus" "dynatron.me/x/blasphem/pkg/config" + "dynatron.me/x/blasphem/pkg/frontend" ) type Server struct { @@ -28,7 +30,13 @@ func New(cfg *config.Config) (*Server, error) { cfg: cfg, } + rootFS, err := fs.Sub(frontend.Root, "frontend/hass_frontend") + if err != nil { + return nil, err + } + mux.HandleFunc("/api/websocket", s.wsHandler) + mux.Handle("/", http.FileServer(http.FS(rootFS))) return s, nil }