2022-07-10 09:02:56 +08:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"embed"
|
|
|
|
"io/fs"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/labstack/echo/v4"
|
2022-07-15 21:25:29 +08:00
|
|
|
"github.com/labstack/echo/v4/middleware"
|
2022-07-10 09:02:56 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
//go:embed dist
|
|
|
|
var embeddedFiles embed.FS
|
|
|
|
|
|
|
|
func getFileSystem() http.FileSystem {
|
|
|
|
fs, err := fs.Sub(embeddedFiles, "dist")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return http.FS(fs)
|
|
|
|
}
|
|
|
|
|
|
|
|
func embedFrontend(e *echo.Echo) {
|
2022-07-15 21:25:29 +08:00
|
|
|
e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
|
|
|
|
HTML5: true,
|
|
|
|
Filesystem: getFileSystem(),
|
|
|
|
}))
|
2022-07-10 09:02:56 +08:00
|
|
|
}
|