@onlineapps/service-wrapper 2.2.8 → 2.2.9
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/createTenantContextMiddleware.js +4 -1
- package/src/index.js +11 -2
package/package.json
CHANGED
|
@@ -54,7 +54,10 @@ function createTenantContextMiddleware(options = {}) {
|
|
|
54
54
|
|
|
55
55
|
function sendJson(res, statusCode, payload) {
|
|
56
56
|
if (!res || typeof res.status !== 'function' || typeof res.json !== 'function') {
|
|
57
|
-
throw new Error(
|
|
57
|
+
throw new Error(
|
|
58
|
+
'[service-wrapper][TenantContext] res.status/res.json unavailable - ' +
|
|
59
|
+
'middleware is likely running before expressInit (check bootstrap stack order)'
|
|
60
|
+
);
|
|
58
61
|
}
|
|
59
62
|
return res.status(statusCode).json(payload);
|
|
60
63
|
}
|
package/src/index.js
CHANGED
|
@@ -93,7 +93,16 @@ async function bootstrap(serviceRoot, options = {}) {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
stack.pop();
|
|
96
|
-
|
|
96
|
+
// Insert AFTER expressInit (which sets up res.status/res.json via setPrototypeOf).
|
|
97
|
+
// Position 0 = query, 1 = expressInit. Tenant context must run after both.
|
|
98
|
+
const expressInitIdx = stack.findIndex(l => l.name === 'expressInit');
|
|
99
|
+
if (expressInitIdx === -1) {
|
|
100
|
+
throw new Error(
|
|
101
|
+
'[service-wrapper][TenantContext] Express stack missing expressInit layer - ' +
|
|
102
|
+
'cannot guarantee tenant context runs after Express initialization'
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
stack.splice(expressInitIdx + 1, 0, lastLayer);
|
|
97
106
|
|
|
98
107
|
// Register /health route BEFORE service's 404 handler.
|
|
99
108
|
// ServiceWrapper._setupHealthChecks() will later set _healthImpl with actual MQ checks.
|
|
@@ -111,7 +120,7 @@ async function bootstrap(serviceRoot, options = {}) {
|
|
|
111
120
|
const healthLayer = stack.pop();
|
|
112
121
|
if (healthLayer) {
|
|
113
122
|
const catchAllIdx = stack.findIndex((layer, i) =>
|
|
114
|
-
i > 0 && !layer.route && !['query', 'expressInit', 'jsonParser', 'urlencodedParser'].includes(layer.name)
|
|
123
|
+
i > 0 && !layer.route && !['query', 'expressInit', 'tenantContextMiddleware', 'jsonParser', 'urlencodedParser'].includes(layer.name)
|
|
115
124
|
);
|
|
116
125
|
if (catchAllIdx > 0) {
|
|
117
126
|
stack.splice(catchAllIdx, 0, healthLayer);
|