I'm trying to serve a folder in the root of my application called assets
. I want all files and subfolders within there to be accessible through the url /details/
.
fs := http.FileServer(http.Dir("assets"))
http.Handle("/details/", http.StripPrefix("/details/", fs))
I still get 404s for everything. Am I using StripPrefix
incorrectly?
To be clear, suppose assets
contained test.json
. I want that to be accessible from the URL /details/test.json
.
Per the above comments double check your paths, permission, user contexts etc.
If you are still stuck, start with this basic setup:
package main
import (
"log"
"net/http"
)
func main() {
fs := http.FileServer(http.Dir("/tmp/assets"))
http.Handle("/details/", http.StripPrefix("/details/", fs))
log.Fatal(
http.ListenAndServe(":8080", nil),
)
}
And test with curl etc.
$ find /tmp/assets
/tmp/assets
/tmp/assets/test.json
$ go run ./main.go
$ curl localhost:8080/details/
<pre>
<a href="test.json">test.json</a>
</pre>