serve site from filesystem rather than embedding It's cool to embed, but it requires server.go to be at the root. Also, I'd like to be able to update the built site separately in the future.
1 file changed, 2 insertions(+), 7 deletions(-)
changed files
M server.go → server.go
@@ -1,7 +1,6 @@ package main import ( - "embed" "errors" "fmt" "io"@@ -44,9 +43,6 @@ type Host struct { Fiber *fiber.App } - -//go:embed all:public/* -var fs embed.FS var Commit string@@ -130,10 +126,10 @@ })) website.Use(recover.New(recover.Config{})) - files := http.FS(fs) + files := http.Dir("public") notFoundHandler := func(c *fiber.Ctx) error { c.Status(fiber.StatusNotFound).Type("html", "utf-8") - content, err := files.Open("public/404.html") + content, err := files.Open("404.html") if err != nil { c.Type("txt") return c.SendString("404 Not Found")@@ -143,7 +139,6 @@ } website.Get("/404.html", notFoundHandler) website.Use("/", filesystem.New(filesystem.Config{ Root: files, - PathPrefix: "public", ContentTypeCharset: "utf-8", MaxAge: int((24 * time.Hour).Seconds()), }))