UNPKG

jovo-framework

Version:

[![Jovo Framework](../docs/img/jovo-header.png)](https://www.jovo.tech)

69 lines 2.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const jovo_core_1 = require("jovo-core"); if (process.env.LAMBDA_TASK_ROOT && process.env.AWS_EXECUTION_ENV) { if (jovo_core_1.Log.config.appenders['console']) { jovo_core_1.Log.config.appenders['console'].ignoreFormatting = true; } } class Lambda { constructor(event, context, callback) { this.isApiGateway = false; this.hasWriteFileAccess = false; this.event = event; this.context = context; this.callback = callback; if (event.body) { this.isApiGateway = true; this.$request = (typeof event.body === 'string') ? JSON.parse(event.body) : event.body; } else { this.$request = event; } } getRequestObject() { return this.$request; } setResponse(obj) { return new Promise((resolve) => { if (this.isApiGateway) { this.callback(null, { statusCode: 200, body: JSON.stringify(obj), isBase64Encoded: false, headers: { 'Content-Type': 'application/json; charset=utf-8', }, }); } else { this.callback(null, obj); } resolve(); }); } fail(error) { const responseObj = { code: 500, msg: error.message, }; if (process.env.NODE_ENV === 'production') { responseObj.stack = error.stack; } if (this.isApiGateway) { this.callback(error, { statusCode: 500, body: JSON.stringify(responseObj), isBase64Encoded: false, headers: { 'Content-Type': 'application/json; charset=utf-8', }, }); } else { this.callback(error, responseObj); } } } exports.Lambda = Lambda; //# sourceMappingURL=Lambda.js.map