nareshbhatia / proshop-nx

Sample shopping app using the Nx monorepo
proshop-nx-catalog.vercel.app
2 stars 0 forks source link

Client side of Next apps is not able to access proshop-api #1

Closed nareshbhatia closed 2 years ago

nareshbhatia commented 2 years ago

In docker-compose.yaml, we specify the NX_API_URL environment variable as follows:

  proshop-catalog:
    image: nareshbhatia/proshop-nx-catalog:1.0.0
    ports:
      - '3001:3001'
    depends_on:
      - proshop-api
    environment:
      - NX_API_URL=http://proshop-api:8080

  proshop-api:
    image: nareshbhatia/proshop-nx-api:1.0.0
    ports:
      - '8080:8080'

This works for the server side, but client side is not able to access http://proshop-api:8080. The proshop-api domain is not known to the client.

We were able to work around this issue when deploying individual docker containers by specifying actual IP address of the machine. For example:

docker run -d --name proshop-nx-catalog -p 3001:3001 -e NX_API_URL=http://192.168.86.247:8080 nareshbhatia/proshop-nx-catalog:1.0.0

But this is a pure hack!!

themegaphoenix commented 2 years ago

I am not familiar with GraphQL, but any reason why GraphQL is not exposed as /graphql endpoint that the Front-End use with NGNIX routing it? With proper authentication it should not be a problem

nareshbhatia commented 2 years ago

This is a good idea. Let me explore further.

nareshbhatia commented 2 years ago

Thanks @themegaphoenix, I was able to do this successfully. Note that there was an additional complication - the relative URL works only client-side, server side must use the docker network URL. I have handled this when initializing the Apollo Client. See here.