Skip to content

Commit 2dbaaf0

Browse files
committed
fix: strip trailing slashes in proxy pathRewrite and disable strict routing in patient-service
1 parent 4881397 commit 2dbaaf0

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

api-gateway/src/app.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,16 @@ app.use(
105105
createProxyMiddleware({
106106
target: process.env.PATIENT_SERVICE_URL || 'http://localhost:3001',
107107
changeOrigin: true,
108-
pathRewrite: (path) => `/admissions${path}`,
108+
pathRewrite: (path) =>
109+
`/admissions${path}`.replace(/\/$/, '') || '/admissions',
109110
on: {
110111
error: (err: any, req: any, res: any) => {
111112
console.error('[Gateway] /admissions proxy error:', err.message);
112113
if (!res.headersSent) {
113-
res
114-
.status(502)
115-
.json({
116-
error: 'Patient service unavailable',
117-
details: err.message,
118-
});
114+
res.status(502).json({
115+
error: 'Patient service unavailable',
116+
details: err.message,
117+
});
119118
}
120119
},
121120
},
@@ -140,17 +139,16 @@ app.use(
140139
createProxyMiddleware({
141140
target: process.env.PATIENT_SERVICE_URL || 'http://localhost:3001',
142141
changeOrigin: true,
143-
pathRewrite: (path) => `/appointments${path}`,
142+
pathRewrite: (path) =>
143+
`/appointments${path}`.replace(/\/$/, '') || '/appointments',
144144
on: {
145145
error: (err: any, req: any, res: any) => {
146146
console.error('[Gateway] /appointments proxy error:', err.message);
147147
if (!res.headersSent) {
148-
res
149-
.status(502)
150-
.json({
151-
error: 'Patient service unavailable',
152-
details: err.message,
153-
});
148+
res.status(502).json({
149+
error: 'Patient service unavailable',
150+
details: err.message,
151+
});
154152
}
155153
},
156154
},

services/patient-service/src/app.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import appointmentRoutes from './modules/appointments/appointment.routes';
99
import admissionRoutes from './modules/admissions/admission.routes';
1010
const app = express();
1111

12+
// Normalize trailing slashes (Nginx may redirect /foo -> /foo/)
13+
app.set('strict routing', false);
14+
1215
// Middleware
1316
app.use(cookieParser());
1417
app.use(express.json());

0 commit comments

Comments
 (0)