update dependency, fixes for logger update
[websub-hub] / src / service.js
index e76959978eddab7a554dbe80eb4d31ffa9c10d8a..b49882989e7544e40a5f368f3f7dcd8a133c9487 100644 (file)
@@ -15,12 +15,12 @@ const path = require('path');
 const _fileScope = common.fileScope(__filename);
 
 class Service extends Dingus {
-  constructor(logger, db, options) {
+  constructor(logger, db, options, asyncLocalStorage) {
     super(logger, {
       ...options.dingus,
       ignoreTrailingSlash: false,
     });
-
+    this.asyncLocalStorage = asyncLocalStorage;
     this.manager = new Manager(logger, db, options);
     this.authenticator = new Authenticator(logger, db, options);
     this.sessionManager = new SessionManager(logger, this.authenticator, options);
@@ -70,6 +70,17 @@ class Service extends Dingus {
   }
 
 
+  /**
+   * Rearrange logging data.
+   */
+  async preHandler(req, res, ctx) {
+    await super.preHandler(req, res, ctx);
+    const logObject = this.asyncLocalStorage.getStore();
+    logObject.requestId = ctx.requestId;
+    delete ctx.requestId;
+  }
+
+
   /**
    * @param {http.ClientRequest} req
    * @param {http.ServerResponse} res