update dependencies and devDependencies, update eslint config, address lint issues
[squeep-indie-auther] / src / service.js
index 2a159a9181c7b4d327282035c014a4e87a194e55..b26da2f0fa5fa1f6a9f881357ca076196218a5ab 100644 (file)
@@ -13,6 +13,7 @@ const { Authenticator, SessionManager } = require('@squeep/authentication-module
 const { ResourceAuthenticator } = require('@squeep/resource-authentication-module');
 const { TemplateHelper: { initContext } } = require('@squeep/html-template-helper');
 const Enum = require('./enum');
+const { ResponseError } = require('./errors');
 
 const _fileScope = common.fileScope(__filename);
 
@@ -55,6 +56,9 @@ class Service extends Dingus {
     // Information page about service
     this.on(['GET'], '/', this.handlerGetRoot.bind(this));
 
+    // Temmporary to see what rando payload someone is sending us unsolicited
+    this.on(['POST'], '/', this.handlerWhaGwan.bind(this));
+
     // Give load-balancers something to check
     this.on(['GET'], route('healthcheck'), this.handlerGetHealthcheck.bind(this));
 
@@ -101,12 +105,19 @@ class Service extends Dingus {
    * @param {Object} ctx
    */
   async preHandler(req, res, ctx) {
+    const _scope = _fileScope('preHandler');
+
     await super.preHandler(req, res, ctx);
     ctx.url = req.url; // Persist this for logout redirect
 
     const logObject = this.asyncLocalStorage.getStore();
-    logObject.requestId = ctx.requestId;
-    delete ctx.requestId;
+    // istanbul ignore else
+    if (logObject) { // Debugging in vscode seems to kill ALS, work around
+      logObject.requestId = ctx.requestId;
+      delete ctx.requestId;
+    } else {
+      this.logger.debug(_scope, 'no async local store');
+    }
   }
 
 
@@ -466,6 +477,15 @@ class Service extends Dingus {
   }
 
 
+  /**
+   * Temporary to see what an unsolicited payload contains.
+   */
+  async handlerWhaGwan(req, res, ctx) {
+    this.setResponseType(this.responseTypes, req, res, ctx);
+    await this.ingestBody(req, res, ctx);
+    throw new ResponseError(Enum.ErrorResponse.MethodNotAllowed);
+  }
+
   /**
    * @param {http.IncomingMessage} req 
    * @param {http.ServerResponse} res