UNPKG

@gabliam/express

Version:
50 lines (49 loc) 1.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.send = exports.converterValue = void 0; const web_core_1 = require("@gabliam/web-core"); const converterValue = (ctx, execCtx, result) => { // response handler if the result is a ResponseEntity function convertEntity(value) { if (value.hasHeader()) { ctx.response.set(value.headers); } ctx.status = value.status; ctx.body = value.body; } if (!ctx.headersSent) { if (result !== undefined) { if (result instanceof web_core_1.ResponseEntity) { convertEntity(result); } else if (typeof result === 'string' || typeof result === 'object') { ctx.body = result; } else { ctx.body = `${result}`; } } } }; exports.converterValue = converterValue; const send = (ctx, res, json) => { const { status, message, body, type } = ctx; /* istanbul ignore next */ if (type) { res.type(type); } /* istanbul ignore next */ if (message) { res.statusMessage = message; } if (status) { res.status(status); } if (json) { res.json(body); } else { res.send(body); } }; exports.send = send;