UNPKG

@cashfarm/tractor

Version:

A Hapi server with superpowers

43 lines 1.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const Hapi = require("hapi"); const Boom = require("boom"); const decorators_1 = require("../decorators"); const decorators_2 = require("../decorators"); /** * Catch-all controller * * This controller's route `notFound` will catch any request for * routes that are not matched by any existing controller * * @export * @class NotFoundCtrl * @implements {IController} */ let NotFoundCtrl = class NotFoundCtrl { notFound(req, reply) { let accept = req.raw.req.headers.accept; accept = (Array.isArray(accept) ? accept.join() : accept); if (accept && accept.match(/json/)) { const err = Boom.notFound('Endpoint not found', { url: req.url }); err.output.payload.data = err.data; return reply(err); } reply().code(404); } }; tslib_1.__decorate([ decorators_2.Endpoint('GET', '/{any*}', { description: 'Matchs any url to log 404 requests', tags: ['api'] }), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [Hapi.Request, Function]), tslib_1.__metadata("design:returntype", void 0) ], NotFoundCtrl.prototype, "notFound", null); NotFoundCtrl = tslib_1.__decorate([ decorators_1.Controller ], NotFoundCtrl); exports.NotFoundCtrl = NotFoundCtrl; //# sourceMappingURL=notFound.js.map