Found a lot of questions on SO exactly handling this topic. But all the examples are not working for me :(.
I’m using GO Web-App with CHI Router, but i’m unable to serve static files. This is my File Structure:
<code>- cmd
- main.go
- assets
- style.css
- views
- someView.templ
</code>
<code>- cmd
- main.go
- assets
- style.css
- views
- someView.templ
</code>
- cmd
- main.go
- assets
- style.css
- views
- someView.templ
Now I want to serve all files within “assets” directory. But always get a 404 Not Found.
My very simple main.go:
<code>func main() {
router := chi.NewRouter()
router.Get("/", indexHandler)
router.Get("/showExternalProfile", showExternalProfileHandler)
router.Post("/project_request", projectRequestHandler)
router.Post("/downloadExternalProfile", downloadExternalProfileHandler)
router.Post("/aigenerateProfile", aibeautifyHandler)
router.Post("/project_clear", clearHandler)
router.Handle("/assets/*", http.FileServer(http.Dir("./assets")))
http.ListenAndServe(":8000", router)
}
</code>
<code>func main() {
router := chi.NewRouter()
router.Get("/", indexHandler)
router.Get("/showExternalProfile", showExternalProfileHandler)
router.Post("/project_request", projectRequestHandler)
router.Post("/downloadExternalProfile", downloadExternalProfileHandler)
router.Post("/aigenerateProfile", aibeautifyHandler)
router.Post("/project_clear", clearHandler)
router.Handle("/assets/*", http.FileServer(http.Dir("./assets")))
http.ListenAndServe(":8000", router)
}
</code>
func main() {
router := chi.NewRouter()
router.Get("/", indexHandler)
router.Get("/showExternalProfile", showExternalProfileHandler)
router.Post("/project_request", projectRequestHandler)
router.Post("/downloadExternalProfile", downloadExternalProfileHandler)
router.Post("/aigenerateProfile", aibeautifyHandler)
router.Post("/project_clear", clearHandler)
router.Handle("/assets/*", http.FileServer(http.Dir("./assets")))
http.ListenAndServe(":8000", router)
}
Already tried different stuff, like “./assets” or “assets” in http.dir or /assets/* and /assets/ within Handle.
Someone has an idea?