Reputation: 918
Having this simple snippet:
fs := http.FileServer(http.Dir("./web/js"))
http.Handle("/js/", http.StripPrefix("/js/", fs))
and going to /js/
actually lists the files, but when I try to open the actual file it says 404 Not Found
$ curl http://localhost:8100/js/
<pre>
<a href="test.js">test.js</a>
</pre>
$ curl http://localhost:8100/js/test.js
404 page not found
Any suggestions? It seems like a super trivial issue.
Upvotes: 0
Views: 85
Reputation: 918
The problem was not in the code snippet, but rather obscuring details like using gorilla/mux
which serves files differently as pointed in this solution:
TLDR:
import "github.com/gorilla/mux"
// snip
router := mux.NewRouter()
fs := http.FileServer(http.Dir("./web/js"))
router.Handle("/js/{.js}", http.StripPrefix("/js/", fs))
Upvotes: 3