X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=src%2Fservice.js;h=df894011dc84f7cad424467b9e62720d4890f9d4;hb=737fbd003d5c4dfea81b667ef906f1c106a60612;hp=d493f8affdf83f3585973ad380c3f9a5ab8caa48;hpb=3bc885c4b6ef8e5ced2ee9708194523a41ebfe7a;p=websub-hub diff --git a/src/service.js b/src/service.js index d493f8a..df89401 100644 --- a/src/service.js +++ b/src/service.js @@ -52,6 +52,7 @@ class Service extends Dingus { this.on(['GET', 'HEAD'], '/admin', this.handlerRedirect.bind(this), `${options.dingus.proxyPrefix}/admin/`); this.on(['GET', 'HEAD'], '/admin/', this.handlerGetAdminOverview.bind(this)); this.on(['GET', 'HEAD'], '/admin/topic/:topicId', this.handlerGetAdminTopicDetails.bind(this)); + this.on(['GET', 'HEAD'], '/admin/topic/:topicId/history.svg', this.handlerGetHistorySVG.bind(this)); // Private data-editing endpoints this.on(['PATCH', 'DELETE'], '/admin/topic/:topicId', this.handlerUpdateTopic.bind(this)); @@ -68,6 +69,24 @@ class Service extends Dingus { } + /** + * Wrap the Dingus head handler, to remove the response body from the context, + * lest it be logged. + * @param {http.ClientRequest} req + * @param {http.ServerResponse} res + * @param {object} ctx + */ + static setHeadHandler(req, res, ctx) { + if (req.method === 'HEAD') { + Dingus.setHeadHandler(req, res, ctx); + const origEnd = res.end.bind(res); + res.end = function (data, encoding, ...rest) { + const origResult = origEnd(data, encoding, ...rest); + delete ctx.responseBody; + return origResult; + }; + } + } /** * @param {http.ClientRequest} req @@ -97,7 +116,7 @@ class Service extends Dingus { ]; this.logger.debug(_scope, 'called', { req: common.requestLogData(req), ctx }); - Dingus.setHeadHandler(req, res, ctx); + Service.setHeadHandler(req, res, ctx); this.setResponseType(responseTypes, req, res, ctx); @@ -116,7 +135,7 @@ class Service extends Dingus { const _scope = _fileScope('handlerGetHealthcheck'); this.logger.debug(_scope, 'called', { req: common.requestLogData(req), ctx }); - Dingus.setHeadHandler(req, res, ctx); + Service.setHeadHandler(req, res, ctx); this.setResponseType(this.responseTypes, req, res, ctx); @@ -135,7 +154,7 @@ class Service extends Dingus { const responseTypes = [...this.responseTypes, Enum.ContentType.ImageSVG]; - Dingus.setHeadHandler(req, res, ctx); + Service.setHeadHandler(req, res, ctx); this.setResponseType(responseTypes, req, res, ctx); @@ -143,6 +162,20 @@ class Service extends Dingus { } + async handlerGetHistorySVG(req, res, ctx) { + const _scope = _fileScope('handlerGetHist'); + this.logger.debug(_scope, 'called', { req: common.requestLogData(req), ctx }); + + const responseTypes = [Enum.ContentType.ImageSVG]; + + Service.setHeadHandler(req, res, ctx); + + this.setResponseType(responseTypes, req, res, ctx); + + await this.manager.getHistorySVG(res, ctx); + } + + /** * @param {http.ClientRequest} req * @param {http.ServerResponse} res @@ -152,7 +185,7 @@ class Service extends Dingus { const _scope = _fileScope('handlerGetAdminOverview'); this.logger.debug(_scope, 'called', { req: common.requestLogData(req), ctx }); - Dingus.setHeadHandler(req, res, ctx); + Service.setHeadHandler(req, res, ctx); this.setResponseType(this.responseTypes, req, res, ctx); @@ -171,7 +204,7 @@ class Service extends Dingus { const _scope = _fileScope('handlerGetAdminTopicDetails'); this.logger.debug(_scope, 'called', { req: common.requestLogData(req), ctx }); - Dingus.setHeadHandler(req, res, ctx); + Service.setHeadHandler(req, res, ctx); this.setResponseType(this.responseTypes, req, res, ctx); @@ -264,7 +297,7 @@ class Service extends Dingus { const _scope = _fileScope('handlerGetAdminLogin'); this.logger.debug(_scope, 'called', { req: common.requestLogData(req), ctx }); - Dingus.setHeadHandler(req, res, ctx); + Service.setHeadHandler(req, res, ctx); this.setResponseType(this.responseTypes, req, res, ctx);