https://garden.io logo
#🌱|help-and-getting-started
help connecting backend to frontend
# 🌱|help-and-getting-started
f

few-magazine-85406

07/18/2023, 4:22 AM
garden version: 0.13.8 rust: 1.70 node:18.16.0-alpine running Linux dev 5.10.102.1-microsoft-standard-WSL2 --- Sorry for the n00b question but I'm at my wit's end. I have a rust backend with a node frontend, both copies of examples from the examples directory from Garden's github. The only thing different is that I've changed the routes so that they should correspond. Here is the repo: https://github.com/matthewaerose/test-of-rust-with-frontend I can reach the backend through its ingress I can reach the frontend through its ingress But when it comes time for the frontend to contact the backend, I get
Copy code
{
  "error": {
    "cause": {
      "errno": -111,
      "code": "ECONNREFUSED",
      "syscall": "connect",
      "address": "127.0.0.1",
      "port": 80
    }
  },
  "message": "Unable to reach service at http://backend.rust.local.demo.garden"
}
--- I check the svc with
kubectl get svc
and see it doesn't have an ExternalIP.
Copy code
NAME       TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
backend    ClusterIP   10.105.208.217   <none>        80/TCP     21m
frontend   ClusterIP   10.97.105.9      <none>        8080/TCP   16m
--- I execute a curl from ingress pod to backend and it returns
Copy code
kephalos@dev:~/test-of-rust-with-frontend$ k exec -n garden-system garden-nginx-ingress-nginx-controller-j9gff -- curl -X GET backend.rust.local.demo.garden
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    17  100    17    0     0     55      0 --:--:-- --:--:-- --:--:--    55Hello, Rust 🦀!
Please let me know if there is any additional info I could provide that could be helpful. Thank you!
q

quaint-dress-831

07/18/2023, 8:14 AM
Hi @few-magazine-85406 thanks for asking Kapa before opening a post and welcome to our community 👋 . I'm taking a look at this now.
@few-magazine-85406, what are you using for local Kubernetes? I'm debugging this with @astonishing-tomato-18259, one of Garden's friendly core devs and we also appear to be running into the same issues you're experiencing when using minikube. So this doesn't appear to be a “you issue”. This is obviously quite a serious issue we're working on solving: we'll keep you updated!
When you say, > I have a rust backend with a node frontend, both copies of examples from the examples directory from Garden's github. The only thing different is that I've changed the routes so that they should correspond. It looks like you've based your examples on
examples/demo-project
is that correct?
a

astonishing-tomato-18259

07/18/2023, 11:19 AM
@few-magazine-85406 Thank you for providing the repo. I just tried it out and the reason you are running into
ECONNREFUSED
error is because the backend URL that you have specified in frontend/app.js is not correct. please change
Copy code
const backendServiceEndpoint = `http://backend.rust.local.demo.garden`
with
Copy code
const backendServiceEndpoint = `http://backend/`
Basically, you do not need to specify the ingress URL there but rather use the service url as it's service-to-service communication between the frontend & backend services inside your namespace. Please give it a try and let us know if it still doesn't work.
f

few-magazine-85406

07/18/2023, 11:55 AM
@astonishing-tomato-18259 @quaint-dress-831 thank you for the responses! I've tried out your suggestion and it works! But I don't understand why. My understanding was that the browser was the one making the call and wouldn't have any idea of
http://backend
. I've even removed the ingress from the backend.garden.yaml and it still works, thinking maybe there was some "behind the scenes magic" happening. I thought the flow would be
browser->DNS->loadBalancer->service
. How is the browser able to hit the service directly?
a

astonishing-tomato-18259

07/18/2023, 11:59 AM
If you look at the code: https://github.com/matthewaerose/test-of-rust-with-frontend/blob/master/frontend/app.js#L10 frontend is basically a node/express service that simply exposes 2 endpoints
/hello-frontend
and
/call-backend
. So browser isn't responsible for calling the backend here but rather the frontend node/express service is responsible for calling the backend. The name frontend migth be a bit confusing here but in fact the backend & frontend in /demo-project are 2 nodejs services.
Also, if you would inspect the network XHR calls in your browser, you won't any call from browser to backend there for the same reason.
3 Views