Skip to content

Commit d7003a6

Browse files
committed
api-gateway corrected
1 parent 72a4bba commit d7003a6

6 files changed

Lines changed: 62 additions & 35 deletions

File tree

api-gateway/src/app.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
import express from 'express';
22
import healthRouter from './routes/health';
33
import { patientProxy } from './proxy/patient.proxy';
4-
import { staffProxy } from './proxy/staff.proxy';
54

65
const app = express();
76

8-
app.use(express.json());
7+
// Debug middleware
8+
app.use((req, res, next) => {
9+
console.log(' GATEWAY REQUEST:', req.method, req.originalUrl);
10+
next();
11+
});
912

1013
app.use('/health', healthRouter);
11-
1214
app.use('/patients', patientProxy);
13-
app.use('/staff', staffProxy);
15+
16+
// ✅ FIXED catch-all route
17+
app.use((req, res) => {
18+
console.log(' NO ROUTE MATCHED:', req.method, req.originalUrl);
19+
res.status(404).json({
20+
error: 'Route not found in gateway',
21+
method: req.method,
22+
url: req.originalUrl,
23+
timestamp: new Date().toISOString(),
24+
});
25+
});
1426

1527
export default app;

api-gateway/src/proxy/patient.proxy.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import { createProxyMiddleware } from 'http-proxy-middleware';
33
export const patientProxy = createProxyMiddleware({
44
target: 'http://localhost:3001',
55
changeOrigin: true,
6-
pathRewrite: {
7-
'^/patients': '',
6+
7+
// ✅ add back /patients prefix
8+
pathRewrite: (path) => `/patients${path}`,
9+
10+
on: {
11+
proxyReq: (proxyReq, req) => {
12+
console.log(' GATEWAY PROXY:', req.method, req.url, '->', proxyReq.path);
13+
},
814
},
915
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { createProxyMiddleware } from 'http-proxy-middleware';
2+
3+
// SUPER SIMPLE - no options that could interfere
4+
const testProxy = createProxyMiddleware({
5+
target: 'http://localhost:3001',
6+
changeOrigin: true,
7+
});
8+
9+
export { testProxy };

pnpm-lock.yaml

Lines changed: 26 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

services/patient-service/src/app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import patientRoutes from './modules/patients/patient.routes.js';
55
const app = express();
66
app.use(express.json());
77

8-
// app.use('/health', healthRouter);
9-
app.use('/health', patientRoutes);
8+
app.use('/health', healthRouter);
9+
app.use('/patients', patientRoutes);
1010

1111
export default app;

services/patient-service/src/modules/patients/patient.routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010

1111
const router = Router();
1212

13-
router.post('/', createPatient);
13+
router.post('/create', createPatient);
1414
router.get('/:id', getPatient);
1515
router.patch('/:id', updatePatient);
1616
router.delete('/:id', deactivatePatient);

0 commit comments

Comments
 (0)