2022-09-25 14:07:47 -04:00
|
|
|
package frontend
|
|
|
|
|
|
|
|
import (
|
|
|
|
"embed"
|
2022-10-29 10:39:06 -04:00
|
|
|
"io"
|
2022-09-30 14:37:40 -04:00
|
|
|
"io/fs"
|
|
|
|
"net/http"
|
2022-10-29 10:39:06 -04:00
|
|
|
|
|
|
|
"github.com/labstack/echo/v4"
|
2022-09-25 14:07:47 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
//go:embed frontend/hass_frontend
|
2022-09-30 14:37:40 -04:00
|
|
|
var root embed.FS
|
|
|
|
|
|
|
|
var RootFS fs.FS
|
|
|
|
|
2022-10-29 10:39:06 -04:00
|
|
|
var FSHandler echo.HandlerFunc
|
|
|
|
|
|
|
|
func AliasHandler(toFile string) echo.HandlerFunc {
|
|
|
|
return func(c echo.Context) error {
|
|
|
|
file, err := RootFS.Open(toFile)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
|
|
|
|
b, err := io.ReadAll(file)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.HTML(http.StatusOK, string(b))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-30 14:37:40 -04:00
|
|
|
func init() {
|
|
|
|
var err error
|
2022-11-11 18:02:52 -05:00
|
|
|
|
2022-09-30 14:37:40 -04:00
|
|
|
RootFS, err = fs.Sub(root, "frontend/hass_frontend")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2022-10-29 10:39:06 -04:00
|
|
|
FSHandler = echo.StaticDirectoryHandler(RootFS, false)
|
2022-09-30 14:37:40 -04:00
|
|
|
}
|