-
Notifications
You must be signed in to change notification settings - Fork 0
Backend API‐Gateway Guide
Heindrich Jansen edited this page May 19, 2026
·
1 revision
The API Gateway is the single entry point for all external traffic. The frontend never calls backend services directly — everything goes through the gateway first.
Port: 3001
Swagger UI: http://localhost:3001/api-docs
Frontend → API Gateway (port 3001) → Accounts Service (port 3002) → Mailing Service (port 3003) ← coming soon
- Frontend sends a request to the gateway
- For protected routes, the gateway validates the JWT using Auth0's public keys
- The gateway forwards the request to the correct downstream service
- The downstream response is passed back to the frontend
| Method | Path | Auth Required |
|---|---|---|
| POST | /api/accounts/auth/register |
No |
| POST | /api/accounts/auth/login |
No |
| GET | /api/accounts/auth/me |
Yes |
- Add the service URL to
.env:
MAILING_SERVICE_URL=http://mailing_app:3003-
Create a controller under
src/your-service/following the same pattern assrc/accounts/accounts.controller.ts -
Use
ProxyServiceto forward requests:
return this.proxy.forward({
url: `${this.serviceUrl}/api/endpoint`,
method: 'POST',
data: body,
});- Register the module in
app.module.ts
Add @UseGuards(JwtAuthGuard) to any route requiring authentication.
After validation req.user contains:
{ auth0Id: string, email: string, role: 'user' | 'analyst' | 'admin' }# Local dev
pnpm build:api-gateway
cd project/backend/api-gateway && pnpm start:prod
# Docker
pnpm dc:up:backend