I am trying to follow the example as described in the
link: https://github.com/gorilla/mux, to serve a single page application
(Angular) from Go and also to route my endpoints.
My endpoints are not being routed although the index.html is served. My
main function has the following format:
//===
func main() {
getParams()
r := mux.NewRouter()
// Routes consist of a path and a handler function.
//-----------------------------------------------
usersR := r.PathPrefix("/users").Subrouter()
usersR.Path("").Methods(http.MethodPost).HandlerFunc(createUser)
usersR.Path("/{id}").Methods(http.MethodGet).HandlerFunc(getUserByID)
usersR.Path("/`{id}").Methods(http.MethodPut).HandlerFunc(updateUser)
usersR.Path("/{id}").Methods(http.MethodDelete).HandlerFunc(deleteUser)
productR := r.PathPrefix("/product").Subrouter()
productR.Path("").Methods(http.MethodGet).HandlerFunc(getProductInfo)
productR.Path("/{id}").Methods(http.MethodGet).HandlerFunc(getProductID)
c := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowCredentials: true,
})
handler := c.Handler(r)
r.HandleFunc("/stockcount", getStock)
spa := spaHandler{staticPath: "public", indexPath: "index.html"}
r.PathPrefix("/{_:.*}").Handler(spa)
ip := GetOutboundIP()
portAvailable(port)
fmt.Printf("Start listening on %s // %s \n", ip, port)
http.ListenAndServe(":"+port, handler)
}
//===========
All request seems to be handled by the spaHandler so I received a bad
request when trying to reach an endpoint.
500 (Internal Server Error)
Also how do I re-route for path "/home" to the index.html?
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/ce3d1ddc-2c70-48c7-bdc8-1ea0361cc918n%40googlegroups.com.