UNPKG

nralcm

Version:

This is a framework based on NodeJs to manage rest api request lifecycle

37 lines (36 loc) 1.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const express = require("express"); const lifecycle_1 = require("./lifecycle"); const bodyparser = require("body-parser"); const app_config_1 = require("./app-config"); class App { constructor() { this.restApiConfiguration = new lifecycle_1.RestApiConfiguration(); this.httpConfiguration = new lifecycle_1.HttpConfiguration(this.restApiConfiguration); this.express = express(); this.express.use(bodyparser.json()); new app_config_1.AppConfig(this.restApiConfiguration).register(); this.express.use((err, req, res, next) => { if (err) { if (err instanceof SyntaxError) { // console.log("syntax err"); return res.type("application/json").status(400).send({ message: "Invalid Json Body" }); ; } console.log(err); return; } next(); }); this.mountRoutes(); } mountRoutes() { const router = express.Router(); router.all("*", (request, response) => { lifecycle_1.HandlerDispatcher.processHandler(request, response, this.httpConfiguration); }); this.express.use("/", router); } } exports.default = new App().express;