Reputation: 1290
I'm working on a Nativescript mobile application, and at the same time trying to design a Golang backend. I have no experience actually deploying a backend though, so for now i'm just trying to develop locally. So I have some button on my emulated application:
import { Http } from "@angular/http"
+@Component({...}
+export class LoginComponent implements OnInit {...}{
. . .
// <Button ... (tap)="get_test()"></Button>
public get_test(){
this.http.get("http://localhost:8080/");
}
}
And a small web server I copied from the golang website:
package main
import (
"log"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
print("recieved")
}
func main() {
http.HandleFunc("/", handler)
log.Fatal(http.ListenAndServe(":8080", nil))
}
I start up the go
"server":
go build main.go
./main
Now my thinking was that by clicking the button, the command line should print out recieved
and I could use this going forward for designing my requests. Yet nothing happens on either side. There might be plenty of errors here in the code, and i'm not even sure you can emulate this locally. But any help would be appreciated.
Upvotes: 0
Views: 348
Reputation: 2539
There's nothing wrong with your server-side code. It sounds to me like either (a) your frontend code isn't actually triggering the http request (which you should be able to detect by attaching to your browser's debugger) or (b) your frontend is trying to make the request but doesn't know how to find the server (i.e. a networking issue).
Upvotes: 1