From: Justin Wind Date: Fri, 10 Sep 2021 18:43:47 +0000 (-0700) Subject: update dependencies and remove now-redundant functions X-Git-Tag: v1.2.1^2~1 X-Git-Url: http://git.squeep.com/?p=websub-hub;a=commitdiff_plain;h=d32ce0a7ed3840bb3a78f12c35eca0244a34e78a update dependencies and remove now-redundant functions --- diff --git a/package-lock.json b/package-lock.json index 1d7a47a..cca2037 100644 --- a/package-lock.json +++ b/package-lock.json @@ -572,8 +572,8 @@ "dev": true }, "@squeep/api-dingus": { - "version": "git+https://git.squeep.com/squeep-api-dingus/#ca35f167826c0732571da5f35e3c25881d138b79", - "from": "git+https://git.squeep.com/squeep-api-dingus/#v1.1.0", + "version": "git+https://git.squeep.com/squeep-api-dingus/#842a9b1e5b62aa642a53269a8466fd1e021e4ff2", + "from": "git+https://git.squeep.com/squeep-api-dingus/#v1.2.0", "requires": { "mime-db": "^1.49.0", "uuid": "^8.3.2" diff --git a/package.json b/package.json index a76b7d5..95aa708 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "coverage-check" ], "dependencies": { - "@squeep/api-dingus": "git+https://git.squeep.com/squeep-api-dingus/#v1.1.0", + "@squeep/api-dingus": "git+https://git.squeep.com/squeep-api-dingus/#v1.2.0", "@squeep/web-linking": "git+https://git.squeep.com/squeep-web-linking/#v1.0.0", "argon2": "^0.28.2", "axios": "^0.21.4", diff --git a/src/service.js b/src/service.js index c69f6fb..df56ba0 100644 --- a/src/service.js +++ b/src/service.js @@ -40,14 +40,14 @@ class Service extends Dingus { // These routes are intended for accessing static content during development. // In production, a proxy server would likely handle these first. - this.on(['GET', 'HEAD'], '/static', (req, res, ctx) => this.handlerRedirect(req, res, ctx, `${options.dingus.proxyPrefix}/static/`)); - this.on(['GET', 'HEAD'], '/static/', (req, res, ctx) => this.handlerGetStaticFile(req, res, ctx, 'index.html')); + this.on(['GET', 'HEAD'], '/static', this.handlerRedirect.bind(this), `${options.dingus.proxyPrefix}/static/`); + this.on(['GET', 'HEAD'], '/static/', this.handlerGetStaticFile.bind(this), 'index.html'); this.on(['GET', 'HEAD'], '/static/:file', this.handlerGetStaticFile.bind(this)); - this.on(['GET', 'HEAD'], '/favicon.ico', (req, res, ctx) => this.handlerGetStaticFile(req, res, ctx, 'favicon.ico')); - this.on(['GET', 'HEAD'], '/robots.txt', (req, res, ctx) => this.handlerGetStaticFile(req, res, ctx, 'robots.txt')); + this.on(['GET', 'HEAD'], '/favicon.ico', this.handlerGetStaticFile.bind(this), 'favicon.ico'); + this.on(['GET', 'HEAD'], '/robots.txt', this.handlerGetStaticFile.bind(this), 'robots.txt'); // Private informational endpoints - this.on(['GET', 'HEAD'], '/admin', (req, res, ctx) => this.handlerRedirect(req, res, ctx, `${options.dingus.proxyPrefix}/admin/`)); + 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)); @@ -60,22 +60,6 @@ class Service extends Dingus { } - /** - * @param {http.ClientRequest} req - * @param {http.ServerResponse} res - * @param {Object} ctx - * @param {String} newPath - */ - async handlerRedirect(req, res, ctx, newPath) { - const _scope = _fileScope('handlerRedirect'); - this.logger.debug(_scope, 'called', { req: common.requestLogData(req), ctx }); - - res.setHeader(Enum.Header.Location, newPath); - res.statusCode = 307; // Temporary Redirect - res.end(); - } - - /** * @param {http.ClientRequest} req * @param {http.ServerResponse} res @@ -240,25 +224,6 @@ class Service extends Dingus { } - /** - * @param {http.ClientRequest} req - * @param {http.ServerResponse} res - * @param {object} ctx - */ - async handlerGetStaticFile(req, res, ctx, file) { - const _scope = _fileScope('handlerGetStaticFile'); - this.logger.debug(_scope, 'called', { req: common.requestLogData(req), ctx, file }); - - Dingus.setHeadHandler(req, res, ctx); - - // Set a default response type to handle any errors; will be re-set to serve actual static content type. - this.setResponseType(this.responseTypes, req, res, ctx); - - await this.serveFile(req, res, ctx, this.staticPath, file || ctx.params.file); - this.logger.info(_scope, 'finished', { ctx: { ...ctx, responseBody: common.logTruncate((ctx.responseBody || '').toString(), 100) } }); - } - - /** * @param {http.ClientRequest} req * @param {http.ServerResponse} res diff --git a/test/src/service.js b/test/src/service.js index a00b2ce..7a97cf5 100644 --- a/test/src/service.js +++ b/test/src/service.js @@ -60,14 +60,6 @@ describe('Service', function () { }); }); // maybeIngestBody - describe('handlerRedirect', function () { - it('covers', async function () { - await service.handlerRedirect(req, res, ctx, '/'); - assert(res.end.called); - assert.strictEqual(res.statusCode, 307); - }); - }); // handlerRedirect - describe('handlerPostRoot', function () { it('covers public mode', async function () { await service.handlerPostRoot(req, res, ctx); @@ -123,14 +115,6 @@ describe('Service', function () { }) }); // handlerGetAdminTopicDetails - describe('handlerGetStaticFile', function () { - it('covers', async function () { - service.serveFile.resolves(); - await service.handlerGetStaticFile(req, res, ctx); - assert(service.serveFile.called); - }); - }); // handlerGetStaticFile - describe('handlerPostAdminProcess', function () { it('covers', async function () { service.serveFile.resolves();