I use this tutorial to make a web application with GoLang, Angular2 and Dart, but when i start backend by console command 'backend', and route in browser to "localhost:8080/" it must call method from Dart's class "Hello" but it doesn't call, and i get 404 error. All code i got from tutorial and didn't change anything. And i can't find any other tutorials. Can you explain me what wrong am i doing?
GoLang code:
func main() {
http.Handle("/", http.FileServer(http.Dir("./app/web/")))
fmt.Println("Text")
http.HandleFunc("/api/hello", helloWorld)
http.ListenAndServe(":8080", nil)
}
func helloWorld(w http.ResponseWriter, r *http.Request) {
data := struct {
Message string
}{
"Hello, World",
}
if err := json.NewEncoder(w).Encode(data); err != nil {
log.Println(err)
}
}
and angular dart code:
class AppComponent {
Hello hello = new Hello();
}
class Hello{
String message;
Hello(){
HttpRequest.getString('/api/hello')
.then((String content) {
Map parsedMap = JSON.decode(content);
message = parsedMap["Message"];
})
.catchError((Error error) {
print(error.toString());
});
}
}