nralcm
Version:
This is a framework based on NodeJs to manage rest api request lifecycle
32 lines (31 loc) • 1.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const common_1 = require("../../common");
/**
* HandlerDispatcher class dispatches handler for request.
*/
class HandlerDispatcher {
/**
* Method to process handler
* This method process handler that registered in HttpConfiguration
* @param request Request Object
* @param response Response Object
*/
static processHandler(request, response, httpConfiguration, context) {
const matchedHandler = httpConfiguration.getHandler(request.url);
if (matchedHandler && matchedHandler[1]) {
matchedHandler[1].processRequest(request, response);
}
else {
let httpContext;
if (context) {
httpContext = context;
}
else {
httpContext = common_1.getContext(request, response);
}
httpContext.response.type("application/json").status(400).json({ message: "There is no handler supported for the request" });
}
}
}
exports.HandlerDispatcher = HandlerDispatcher;