Fix static file handling for the embedded filesystem
This commit is contained in:
parent
eff740072d
commit
f32223f12c
@ -3,6 +3,7 @@ package routes
|
|||||||
import (
|
import (
|
||||||
"GoWeb/app"
|
"GoWeb/app"
|
||||||
"GoWeb/controllers"
|
"GoWeb/controllers"
|
||||||
|
"io/fs"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
@ -15,8 +16,14 @@ func GetRoutes(app *app.App) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Serve static files
|
// Serve static files
|
||||||
http.Handle("/file/", http.FileServer(http.Dir("./static")))
|
staticFS, err := fs.Sub(app.Res, "static")
|
||||||
log.Println("Serving static files from: ./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
|
// Pages
|
||||||
http.HandleFunc("/", getController.ShowHome)
|
http.HandleFunc("/", getController.ShowHome)
|
||||||
|
Loading…
Reference in New Issue
Block a user