using embeded file system for static files
This commit is contained in:
parent
2cea019aca
commit
4eae59bd66
23
main.go
23
main.go
@ -2,7 +2,9 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"embed"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
@ -12,10 +14,8 @@ import (
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
|
||||
var CurrentConfig = rendering.NewConfig()
|
||||
|
||||
|
||||
func FetchDiyHrt() error {
|
||||
fmt.Println("Fetch DiyHrt Marketplaces...")
|
||||
|
||||
@ -34,6 +34,18 @@ func getIndex(c echo.Context) error {
|
||||
return c.HTML(http.StatusOK, tpl.String())
|
||||
}
|
||||
|
||||
//go:embed frontend/*
|
||||
var frontendFiles embed.FS
|
||||
|
||||
func getFileSystem() http.FileSystem {
|
||||
fsys, err := fs.Sub(frontendFiles, "frontend")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return http.FS(fsys)
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println("running transfem startpage")
|
||||
|
||||
@ -54,8 +66,11 @@ func main() {
|
||||
}
|
||||
|
||||
e := echo.New()
|
||||
e.Static("/assets", "frontend/assets")
|
||||
e.Static("/scripts", "frontend/scripts")
|
||||
// "frontend/assets"
|
||||
|
||||
staticHandler := http.FileServer(getFileSystem())
|
||||
e.GET("/assets/*", echo.WrapHandler(http.StripPrefix("/", staticHandler)))
|
||||
e.GET("/scripts/*", echo.WrapHandler(http.StripPrefix("/", staticHandler)))
|
||||
e.GET("/", getIndex)
|
||||
|
||||
e.Logger.Fatal(e.Start(":" + strconv.Itoa(CurrentConfig.Server.Port)))
|
||||
|
Loading…
x
Reference in New Issue
Block a user