My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

Frontend and API in different containers

Riderman de Sousa Barbosa's photo
Riderman de Sousa Barbosa
·Jun 21, 2017

I have 3 containers for each (Frontend, backend and MongoDB)

  1. Frontend, expose port: 0.0.0.0:80->80/tcp, 443/tcp
  2. API, expose ports: 80/tcp, 443/tcp, 43554/tcp, 0.0.0.0:3000->3000/tcp
  3. MongoDB, expose ports: 0.0.0.0:27017->27017/tcp

To run my API, I just link the MongoDB container

docker run -d -p 3000:3000 --name backend --link mongodb:mongodb backend

In my frontend app, every ajax call will do by /api/

So ...

Front-end (HTML/CSS/JS) make a request to /api/*** , and should redirect to container port :3000 so my API can respond.

How can I do that? both using same url myapp.com for front-end and myapp.com/api for backend.