Closed rngallen closed 1 year ago
Am using file system to save html and static files. Server returns 404 for static files
html
static files
package main import ( "embed" "log" "net/http" "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/middleware/filesystem" "github.com/gofiber/template/html/v2" ) //go:embed views/* var viewsfs embed.FS // var staticfs embed.FS var embedDirStatic embed.FS func main() { engine := html.NewFileSystem(http.FS(viewsfs), ".html") app := fiber.New(fiber.Config{ ServerHeader: "GOFIBER", StrictRouting: true, CaseSensitive: true, AppName: "Go Htmx", Views: engine, ViewsLayout: "views/base/main", }) app.Use("/static", filesystem.New(filesystem.Config{ Root: http.FS(embedDirStatic), PathPrefix: "static", Browse: true, })) app.Get("", func(c *fiber.Ctx) error { return c.Render("views/index", fiber.Map{"Title": "Hello Raheel"}) }) log.Fatal(app.Listen(":3030")) }
Embed comment for the embedDirStatic was missing
Question Description
Am using file system to save
html
andstatic files
. Server returns 404 for static filesCode Snippet (optional)
Checklist: