UNPKG

mgm

Version:

My generic modules

46 lines (40 loc) 1.31 kB
const ThreadLocal = require('../tool/ThreadLocal'); module.exports = class ConfigController { constructor() { this.json = {}; } renderView(req, res, next) { try { var view = req.originalUrl.replace(/\?.*/g, '').replace(/\//g, ""); if (view === '') { view = 'Home'; } this.doClear(); res.render(view, this.getRenderOptions()); } catch (e) { this.renderError(e, req, res, next); } finally { ThreadLocal.clear(); } } async invokeApplication(req, res, next) { try { this.json = req.body; this.updateModel(req, res, next); if (this.json.method.length > 0) { checkMethod.call(this, this.json.method); await this[this.json.method](req, res, next); } this.renderResponse(req, res, next); } catch (e) { this.renderError(e, req, res, next); } finally { ThreadLocal.clear(); } } } function checkMethod(methodName) { if (this[methodName] === undefined) { throw new Error(`No Such Method '${this.constructor.name}.${methodName}' found.`); } }