ARM
ARM

Reputation: 21

Express gateway is not able to access the API and bind with nginx proxy,server response: cannot get

I have some microservices servers connected to the express gateway, the gateway works fine locally but inside the server it cannot access other API routs for expample if I try to get http://xx.xx.xx.xx/api-docs it responds with "cannot get /api-docs" or any other routes but when I try it like so locally http://localhost:4010/api-docs it works just fine any help would be appreciated.

Server specs are linux ubunto 20, nginx 1.18.0, node v18.17.1

Here is my yaml config file the urls are located inside the .env file and it's like this: SWAGGER_DB=http://localhost:4006

http:
  port: ${PORT}
  hostname: 0.0.0.0
admin:
  port: 9876
  host: localhost
apiEndpoints:
  auth:
    host: localhost
    paths: ['/users*', '/auth*', '/admin*']
  catalog:
    host: localhost
    paths: ['/products*', '/tags*', '/sizes*', '/categories*', '/brands*', '/colors*', '/parameters*']
  images:
    host: localhost
    paths: ['/images*']
  orders:
    host: localhost
    paths: ['/addresses*', '/baskets*', '/checkouts*', '/order-products*', '/payments*']
  reviews:
    host: localhost
    paths: ['/reviews*', '/comments*']
  questions:
    host: localhost
    paths: ['/questions*', '/question-comments*']
  swagger:
    host: localhost
    paths: ['/api-docs*']
  wishlists:
    host: localhost
    paths: ['/wishlists*']
  banners:
    host: localhost
    paths: ['/slides*', '/advertisements*']
  analytics:
    host: localhost
    paths: ['/analytics*']
  mailer:
    host: localhost
    paths: ['/subscribe*', '/mailings*']
serviceEndpoints:
  authSrv:
    url: ${AUTH_DB}
  catalogSrv:
    url: ${CATALOG_DB}
  imagesSrv:
    url: ${IMAGES_DB}
  ordersSrv:
    url: ${ORDERS_DB}
  reviewsSrv:
    url: ${REVIEWS_DB}
  questionsSrv:
    url: ${QUESTIONS_DB}
  swaggerSrv:
    url: ${SWAGGER_DB}
  wishlistsSrv:
    url: ${WISHLISTS_DB}
  bannersSrv:
    url: ${BANNERS_DB}
  analyticsSrv:
    url: ${ANALYTICS_DB}
  mailerSrv:
    url: ${MAILER_DB}
policies:
  - cors
  - proxy
pipelines:
  pipeAuth:
    apiEndpoints:
      - auth
    policies:
      - proxy:
          - action:
              serviceEndpoint: authSrv
              changeOrigin: true
  pipeCatalog:
    apiEndpoints:
      - catalog
    policies:
      - proxy:
          - action:
              serviceEndpoint: catalogSrv
              changeOrigin: true
  pipeImages:
    apiEndpoints:
      - images
    policies:
      - proxy:
          - action:
              serviceEndpoint: imagesSrv
              changeOrigin: true
  pipeOrders:
    apiEndpoints:
      - orders
    policies:
      - proxy:
          - action:
              serviceEndpoint: ordersSrv
              changeOrigin: true
  pipeReviews:
    apiEndpoints:
      - reviews
    policies:
      - proxy:
          - action:
              serviceEndpoint: reviewsSrv
              changeOrigin: true
  pipeQuestions:
    apiEndpoints:
      - questions
    policies:
      - proxy:
          - action:
              serviceEndpoint: questionsSrv
              changeOrigin: true
  pipeSwagger:
    apiEndpoints:
      - swagger
    policies:
      - proxy:
          - action:
              serviceEndpoint: swaggerSrv
              changeOrigin: true
  pipeWishlists:
    apiEndpoints:
      - wishlists
    policies:
      - proxy:
          - action:
              serviceEndpoint: wishlistsSrv
              changeOrigin: true
  pipeBanner:
    apiEndpoints:
      - banners
    policies:
      - proxy:
          - action:
              serviceEndpoint: bannersSrv
              changeOrigin: true
  pipeAnalytic:
    apiEndpoints:
      - analytics
    policies:
      - proxy:
          - action:
              serviceEndpoint: analyticsSrv
              changeOrigin: true
  pipeMailer:
    apiEndpoints:
      - mailer
    policies:
      - proxy:
          - action:
              serviceEndpoint: mailerSrv
              changeOrigin: true

The Reverse proxy with Nginx

server {
    server_name xx.xxx.xxx.183; // here is the server ip address

    location / {
        proxy_pass http://localhost:4010;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

I tried this solution but no results How to bind express-gateway

Upvotes: 0

Views: 192

Answers (1)

ARM
ARM

Reputation: 21

the problem was in the apiEndpoints host I found the sluotion in express gateway docs here, I just had to change the host from localhost to my server ip address like so:

apiEndpoints:
  auth:
    host: 192.xxx.xxx.xxx //add your server ip address here
    paths: ['/users*', '/auth*', '/admin*']
  catalog:
    host: 192.xxx.xxx.xxx //add your server ip address here
    paths: ['/products*', '/tags*', '/sizes*', '/categories*', '/brands*', '/colors*', '/parameters*']
  images:
    host: 192.xxx.xxx.xxx //add your server ip address here
    paths: ['/images*']
.
.
.

Upvotes: 1

Related Questions