Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions apis/gateway/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
import express, { Express, Request, Response } from "express";
import proxy from "express-http-proxy";
import rateLimit from "express-rate-limit";

const app: Express = express();

const limiter = rateLimit({
windowMs: 15 * 60 * 1000,
max: 50,
message: 'Too many requests, please try again later.',
});

app.use(limiter);
app.use(express.json());
app.use(express.urlencoded({ extended: true }));

app.get("/", (req: Request, res: Response) => {
res.send("Hello, TypeScript Node Express! Gateway");
});

const auth = proxy("http://authcommand:5000");
const query = proxy("http://authquery:5000");
const authProxy = proxy('http://authcommand:5000', {
preserveHostHdr: true
});

const queryProxy = proxy('http://authquery:5000', {
preserveHostHdr: true
});

app.use("/auth", auth);
app.use('/auth', authProxy);
app.use('/query', queryProxy);

const server = app.listen(8080, () => {
console.log("Gateway is Listening to Port 8080");
Expand Down
3 changes: 2 additions & 1 deletion apis/gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"cors": "^2.8.5",
"dotenv": "^16.4.7",
"express": "^4.21.2",
"express-http-proxy": "^2.1.1"
"express-http-proxy": "^2.1.1",
"express-rate-limit": "^7.5.0"
},
"devDependencies": {
"@types/cors": "^2.8.17",
Expand Down
23 changes: 11 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,27 @@ services:
- "5001:8080"
depends_on:
- authcommand
- authquery

authcommand:
container_name: authcommand
build:
context: ./apis/authCommand
env_file: .env
environment:
- NODE_ENV=production
depends_on:
- "mongodb"

authquery:
container_name: authQuery
build:
context: ./apis/authQuery
env_file: .env
environment:
- NODE_ENV=production

# authquery:
# container_name: authQuery
# build:
# context: ./apis/authQuery
# env_file: .env
# volumes:
# - ./apis:/api
# ports:
# - 8082:3000
# depends_on:
# - mongodb
depends_on:
- mongodb

# MaintenanceCommand:
# container_name: MaintenanceCommand
Expand Down