This repository contains an example of an API gateway created using Express.js and the http-proxy-middleware. This gateway can route specific API routes to different target backend servers and modify requests as needed. For instance, it can route the "/api/authentication" route to a local server, the "/api/community" route to another server, and the "/api/event" route to yet another server.
To run this project in a local environment, you'll need the following:
- Node.js (version 14 or higher recommended)
-
Clone this repository or download it as a ZIP file:
git clone https://github.com/ismailertuglu14/nodejs-api-gateway.git
-
Navigate to the project directory:
cd nodejs-api-gateway
-
Install project dependencies:
npm install
- This API gateway includes an array of route settings called routes. Each route setting defines how a specific API route should be routed and modified. Here's an example route setting:
{ context: "/api/authentication", target: "https://localhost:7232", secure: false, auth: false, changeOrigin: true, pathRewrite: { "^/api/authentication": "/authentication" }, methods: ["GET", "POST", "PUT"], }
Alan | Açıklama |
---|---|
context |
Anahtar bir API rotasını belirtir. |
target |
Yönlendirilen hedef sunucunun URL'sini belirtir. |
secure |
SSL sertifikası gerekip gerekmediğini belirtir (true veya false). |
auth |
Kimlik doğrulama gerekip gerekmediğini belirtir (true veya false). |
changeOrigin |
İstek başlıklarında origin alanının değiştirilip değiştirilmeyeceğini belirtir (true veya false). |
pathRewrite |
Rota yeniden yazma kurallarını tanımlar. |
methods |
Hangi HTTP yöntemlerinin bu rotanın yönlendirilmesine izin verildiğini belirtir. |