Hello,
I have recently tried to deploy an angular2 + golang application.
Super simplified sample of code is as follows:
package main
import (
"net/http"
"github.com/gorilla/mux"
)
func main() {
fs := http.FileServer(http.Dir("./dist"))
r := mux.NewRouter()
// Api routes
// ....
// End Api routes
r.PathPrefix("/").Handler(fs)
http.ListenAndServe(":8081",r)
}
When the page is refreshed, the request is sent to server which results in a page not found error since the request bypasses the router in angular.
So I’ve concluded that this method is only suitable for static file web sites. Please do correct me if I’m wrong.
Method to try over the weekend.
- nginx: to serve angular on port 80
- run golang api server on seperate port(undecided port)
Any suggestions or advice for angular2 + golang web applications? Any norms?
Thanks for feedback.
Edit: grammatical and spelling error. Sorry posting from mobile