Zachscs
Zachscs

Reputation: 3663

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.

Upvotes: 2

Views: 1084

Answers (1)

kars7e
kars7e

Reputation: 786

When using relative paths you have to be extra cautious about the working directory of your application. Try printing the value returned by os.Getwd and see if it makes sense when combined with "path/to/dist".

Also, since http.FileServer checks if path starts with /, and if it doesn't it adds it back, using http.StripPrefix with "/" is not needed.

Upvotes: 3

Related Questions