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);
}
+ /**
+ * 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