Exposing our microservice via an API gateway
We have split our monolith into two microservices. However, we would still need to expose them under a single origin (in web terminology, the origin of a page is the combination of the hostname/IP and the port). How can we do that? We will cover an Nginx-based strategy as well as a Fastify-based one.
docker-compose to emulate a production environment
To demonstrate our deployment scenario, we will be using a
docker-compose setup. Following the same setup as in Chapter 10, let’s create a Dockerfile for each service (v1 and v2). The only relevant change is replacing the
CMD statement at the end of the file, like so:
CMD ["node", "server.js"]
We’ll also need to create the relevant
package.json file for each microservice.
Once everything is set up, we should be able to build and run both v1 and v2 that we just created. To run them, we set up a
docker-compose-two-services.yml file like the following...