Spaces:
Sleeping
Sleeping
Update app.js
Browse files
app.js
CHANGED
|
@@ -11,41 +11,6 @@ const app = express();
|
|
| 11 |
|
| 12 |
// ----
|
| 13 |
|
| 14 |
-
// Trust proxy headers (useful when behind load balancers / host proxies)
|
| 15 |
-
app.set('trust proxy', true);
|
| 16 |
-
|
| 17 |
-
// Normalize incoming path: remove trailing slash in-process (no redirect),
|
| 18 |
-
// so callers can hit /webhook/paystack or /webhook/paystack/ and we won't send redirects.
|
| 19 |
-
// This mutates req.url and keeps query string intact.
|
| 20 |
-
app.use((req, res, next) => {
|
| 21 |
-
try {
|
| 22 |
-
if (req.path && req.path.length > 1 && req.path.endsWith('/')) {
|
| 23 |
-
// remove only trailing slashes from pathname while keeping query string
|
| 24 |
-
const url = req.originalUrl || req.url;
|
| 25 |
-
// split once at '?'
|
| 26 |
-
const [pathPart, q] = url.split('?');
|
| 27 |
-
const normalized = pathPart.replace(/\/+$/, '') + (q ? `?${q}` : '');
|
| 28 |
-
req.url = normalized;
|
| 29 |
-
// Also update req.originalUrl so logs match
|
| 30 |
-
req.originalUrl = normalized;
|
| 31 |
-
}
|
| 32 |
-
} catch (e) {
|
| 33 |
-
// don't break the request flow for any reason
|
| 34 |
-
}
|
| 35 |
-
return next();
|
| 36 |
-
});
|
| 37 |
-
|
| 38 |
-
// Ensure OPTIONS and HEAD don't cause proxies to try redirects or 301 behaviour
|
| 39 |
-
app.options('*', (_req, res) => res.sendStatus(200));
|
| 40 |
-
app.head('*', (_req, res) => res.sendStatus(200));
|
| 41 |
-
|
| 42 |
-
// Optional light logger — helpful to confirm whether requests reach your app.
|
| 43 |
-
// Comment out if you want less noise.
|
| 44 |
-
app.use((req, res, next) => {
|
| 45 |
-
console.log(new Date().toISOString(), req.method, req.originalUrl, '-> ip:', req.ip || req.headers['x-forwarded-for'] || '');
|
| 46 |
-
next();
|
| 47 |
-
});
|
| 48 |
-
|
| 49 |
// ----
|
| 50 |
|
| 51 |
const {
|
|
|
|
| 11 |
|
| 12 |
// ----
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
// ----
|
| 15 |
|
| 16 |
const {
|