@onlineapps/service-wrapper 2.1.113 → 2.1.114
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/ServiceWrapper.js +22 -2
package/package.json
CHANGED
package/src/ServiceWrapper.js
CHANGED
|
@@ -1078,7 +1078,7 @@ class ServiceWrapper {
|
|
|
1078
1078
|
_setupHealthChecks() {
|
|
1079
1079
|
const healthEndpoint = this.config.wrapper?.health?.endpoint || '/health';
|
|
1080
1080
|
|
|
1081
|
-
|
|
1081
|
+
const healthHandler = async (req, res) => {
|
|
1082
1082
|
const health = {
|
|
1083
1083
|
status: 'healthy',
|
|
1084
1084
|
service: this.config.service?.name || 'unnamed-service',
|
|
@@ -1113,7 +1113,27 @@ class ServiceWrapper {
|
|
|
1113
1113
|
}
|
|
1114
1114
|
|
|
1115
1115
|
res.json(health);
|
|
1116
|
-
}
|
|
1116
|
+
};
|
|
1117
|
+
|
|
1118
|
+
// Insert health route BEFORE catch-all 404/error handlers in Express stack.
|
|
1119
|
+
// Services register routes in app.js (loaded before ServiceWrapper), including
|
|
1120
|
+
// 404 middleware. A plain app.get() would add AFTER the 404 handler and never match.
|
|
1121
|
+
this.app.get(healthEndpoint, healthHandler);
|
|
1122
|
+
|
|
1123
|
+
const stack = this.app._router?.stack;
|
|
1124
|
+
if (stack && stack.length > 1) {
|
|
1125
|
+
const healthLayer = stack.pop();
|
|
1126
|
+
// Find first catch-all middleware (no route, not a built-in parser)
|
|
1127
|
+
const builtins = new Set(['query', 'expressInit', 'jsonParser', 'urlencodedParser', 'tenantContext', 'router']);
|
|
1128
|
+
let insertAt = stack.length;
|
|
1129
|
+
for (let i = 0; i < stack.length; i++) {
|
|
1130
|
+
if (!stack[i].route && !builtins.has(stack[i].name)) {
|
|
1131
|
+
insertAt = i;
|
|
1132
|
+
break;
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
stack.splice(insertAt, 0, healthLayer);
|
|
1136
|
+
}
|
|
1117
1137
|
|
|
1118
1138
|
this.logger?.info(`Health check endpoint registered at ${healthEndpoint}`);
|
|
1119
1139
|
|