@lucaapp/service-utils 1.55.18 → 1.56.0
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/dist/lib/api/endpoint.js
CHANGED
|
@@ -117,13 +117,18 @@ const isTypedError = (error) => {
|
|
|
117
117
|
return false;
|
|
118
118
|
return true;
|
|
119
119
|
};
|
|
120
|
-
const validateAndSendResponse = async (expressResponse, response, validResponses, debug) => {
|
|
120
|
+
const validateAndSendResponse = async (expressResponse, response, validResponses, debug, responseHeaders) => {
|
|
121
121
|
try {
|
|
122
122
|
(0, assert_1.default)(typeof response.status === 'number');
|
|
123
123
|
// get schema respective to status code
|
|
124
124
|
const responseSchema = validResponses.find(responseSchema => responseSchema.status === response.status);
|
|
125
125
|
const schema = responseSchema?.schema;
|
|
126
126
|
(0, assert_1.default)(schema);
|
|
127
|
+
if (responseHeaders) {
|
|
128
|
+
Object.entries(responseHeaders).forEach(([header, value]) => {
|
|
129
|
+
expressResponse.set(header, value);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
127
132
|
// validate response schema
|
|
128
133
|
const validatedResponseBody = await schema.parseAsync(response.body);
|
|
129
134
|
if (validatedResponseBody === undefined) {
|
|
@@ -244,7 +249,7 @@ const mountEndpoint = (router, method, path, options, handler, debug) => {
|
|
|
244
249
|
}
|
|
245
250
|
}
|
|
246
251
|
await handler(handlerRequest, ctx, async (controllerResponse) => {
|
|
247
|
-
await validateAndSendResponse(response, controllerResponse, options.responses, debug);
|
|
252
|
+
await validateAndSendResponse(response, controllerResponse, options.responses, debug, options.responseHeaders);
|
|
248
253
|
});
|
|
249
254
|
}
|
|
250
255
|
catch (error) {
|