Load Angular2 Bootstrap template ng2-admin on Go server : download fail

793 views Asked by At

I am new to this forum and a newbie in Angular2 and Golang. My issue is that I would like to try out a template on a Go server.

So, I created a main.go file containing this main() function :

func main() {
    r := mux.NewRouter()
    p := http.StripPrefix("/", http.FileServer(http.Dir("./src/")))
    n := http.StripPrefix("/config", http.FileServer(http.Dir("./config/")))
    r.PathPrefix("/config/").Handler(n)
    r.PathPrefix("/").Handler(p)
    fmt.Printf("Starting server on :33166 \n")
    http.ListenAndServe(":33166", r)
}

and run go run main.go on the project directory, but its fails in this request

GET http://127.0.0.1:33166/webpack-dev-server.js

It might be very simple, but I couldnot figure it out. So, any idea to how I'm able run the project on server would be appreciated. Thanks.

1

There are 1 answers

11
jnmoal On BEST ANSWER

According to the ng2-admin installation guidelines, if you want to use ng2-admin with another backend (golang in your case), you need a release build using the following command:

npm run prebuild:prod && npm run build:prod

From installation guidelines:

This will clear up your dist folder (where release files are located), generate release build (...). Now you can copy the sources from a dist folder and use it with any backend framework or simply put it under some web server.

EDIT: Thanks to @PatrickWalker for his comments.