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.
+ * @param {http.ClientRequest} req
+ * @param {http.ServerResponse} res
+ * @param {Object} ctx
+ */
+ async preHandler(req, res, ctx) {
+ await super.preHandler(req, res, ctx);
+ const logObject = this.asyncLocalStorage.getStore();
+ // FIXME: for some reason, returning from the super.preHandler loses async context?
+ // Workaround until cause and solution are found.
+ if (logObject) {
+ logObject.requestId = ctx.requestId;
+ delete ctx.requestId;
+ }
+ }
+
+
/**
* @param {http.ClientRequest} req
* @param {http.ServerResponse} res