Serving an angular dist folder with go
I'm simply trying to serve an angular application's dist folder using go. I tried an approach which worked well for me with react. e.g.
spa := http.StripPrefix("/", http.FileServer(http.Dir("path/to/dist"))) // m is a gorilla mux router. m.PathPrefix("/").Handler(spa)
However when I navigate to the port I'm serving on I receive a 404 error.
When using relative paths you have to be extra cautious about the working directory of your application. Try printing the value returned by
os.Getwdand see if it makes sense when combined with "path/to/dist".
http.FileServerchecks if path starts with
/, and if it doesn't it adds it back, using
http.StripPrefixwith "/" is not needed.