update dependencies and remove now-redundant functions
authorJustin Wind <justin.wind+git@gmail.com>
Fri, 10 Sep 2021 18:43:47 +0000 (11:43 -0700)
committerJustin Wind <justin.wind+git@gmail.com>
Fri, 10 Sep 2021 18:43:47 +0000 (11:43 -0700)
package-lock.json
package.json
src/service.js
test/src/service.js

index 1d7a47a3620fa669cc4a3ca72479b8a7ab161c41..cca2037efc66ed4a424fed82ad9a5ab0ebc8131b 100644 (file)
       "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"
index a76b7d5e57e8722f90d80e70334874b4cd65ed31..95aa7085ecfd155a30cc300a425176e1ccde8f0c 100644 (file)
@@ -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",
index c69f6fb7c891366dfbe02e659a54414a05da401d..df56ba0ba79137fea5265b91008ef002ae53503c 100644 (file)
@@ -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
index a00b2cea49d882790e8be6e427d913be467af6ff..7a97cf5366f88a70a32702170658b4f2e50c7c97 100644 (file)
@@ -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();