This project demonstrates how to use NodeJS to build a simple API gateway. In this project I learned how to setup unified authentication and authorization, as well as how rate limiting works.
NOTE: This project does not include any persistence layer (database); it only provides an idea of how the API gateway is configured. You can extend this project based on your preferences.
- NodeJS
- TypeScript
- ExpressJS
PORT=8700 -- This port is for the API Gateway
-
Clone the repository
This repository includes two branches: One is the
master
branch, and the other is thelogin-service
branch. These two branches represent two different servers, hence you need to clone them separately.- To clone the
master
branch inside of theapi-gateway
folder:
git clone --branch master https://github.com/adriandotdev/node-ts-api-gateway.git api-gateway
- To clone the
login-service
branch inside of thelogin-service
folder:
git clone --branch login-service https://github.com/adriandotdev/node-ts-api-gateway.git login-service
- To clone the
-
Install dependencies for each application
-
To install all of the dependencies in the
api-gateway
folder:cd /api-gateway
npm install
-
To install all of the dependencies in the
login-service
folder:cd /login-service
npm install
-
-
Create a
.env
file and provide the required variables listed above.Your
.env
file should look like this:PORT=8700
-
Start the two applications.
-
To start the
api-gateway
application:cd /api-gateway
npm run dev
-
To start the
login-service
application:cd /login-service
npm run dev
-
-
That's it! You should see the two applications running.
To request via API gateway to all of your APIs, you need to know what are the paths specified in your routes.
Example is inside of your AuthenticationRoutes.ts
file you can request to:
http://localhost:8700/api/auth/login
http://localhost:8700/api/auth/register
Just look on the path
property.