|
1 | 1 | import express from 'express'; |
2 | | -import healthRouter from './routes/health'; |
3 | | -import { patientProxy } from './proxy/patient.proxy'; |
| 2 | +import cors from 'cors'; |
| 3 | +import healthRoutes from './routes/health'; |
| 4 | +import { patientAuthProxy } from './proxy/patient.auth.proxy'; |
| 5 | +import { patientDataProxy } from './proxy/patient.data.proxy'; |
| 6 | +import { authenticate } from './middlewares/auth.middleware'; |
| 7 | +import { requirePatientSelf } from './middlewares/patient.guard'; |
4 | 8 |
|
5 | 9 | const app = express(); |
6 | 10 |
|
7 | | -// Debug middleware |
8 | | -app.use((req, res, next) => { |
9 | | - console.log(' GATEWAY REQUEST:', req.method, req.originalUrl); |
10 | | - next(); |
11 | | -}); |
| 11 | +app.use(cors()); |
12 | 12 |
|
13 | | -app.use('/health', healthRouter); |
14 | | -app.use('/patients', patientProxy); |
| 13 | +// health |
| 14 | +app.use('/health', healthRoutes); |
15 | 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 | | -}); |
| 16 | +// 🔓 PUBLIC auth (NO JWT) |
| 17 | +app.use('/patients/public', patientAuthProxy); |
| 18 | + |
| 19 | +// 🔐 PROTECTED patient data |
| 20 | +app.use('/patients', authenticate, requirePatientSelf, patientDataProxy); |
26 | 21 |
|
27 | 22 | export default app; |
0 commit comments