From f32223f12ce6c02da8c30ec4ee36eb182eb41273 Mon Sep 17 00:00:00 2001 From: Maximilian Date: Mon, 6 Mar 2023 12:43:54 -0600 Subject: [PATCH] Fix static file handling for the embedded filesystem --- routes/getRoutes.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/routes/getRoutes.go b/routes/getRoutes.go index f0ae6e5..d61a56b 100644 --- a/routes/getRoutes.go +++ b/routes/getRoutes.go @@ -3,6 +3,7 @@ package routes import ( "GoWeb/app" "GoWeb/controllers" + "io/fs" "log" "net/http" ) @@ -15,8 +16,14 @@ func GetRoutes(app *app.App) { } // Serve static files - http.Handle("/file/", http.FileServer(http.Dir("./static"))) - log.Println("Serving static files from: ./static") + staticFS, err := fs.Sub(app.Res, "static") + if err != nil { + log.Println(err) + return + } + staticHandler := http.FileServer(http.FS(staticFS)) + http.Handle("/static/", http.StripPrefix("/static/", staticHandler)) + log.Println("Serving static files from embedded FS") // Pages http.HandleFunc("/", getController.ShowHome)