From 5978cb49194d22e02fe52e42448957f109c169ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Wed, 10 Aug 2016 15:26:14 +0200 Subject: [PATCH] Fix token middleware to not trigger CLS init Rework the token middleware to access current context via `req.loopbackContext` instead of `loopback.getCurentContext()`. That way the CLS/AsyncListener machinery is configured only in applications that are using current context. --- server/middleware/token.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/middleware/token.js b/server/middleware/token.js index b5038df2..21e3b5ca 100644 --- a/server/middleware/token.js +++ b/server/middleware/token.js @@ -124,7 +124,7 @@ function token(options) { TokenModel.findForRequest(req, options, function(err, token) { req.accessToken = token || null; rewriteUserLiteral(req, currentUserLiteral); - var ctx = loopback.getCurrentContext(); + var ctx = req.loopbackContext; if (ctx) ctx.set('accessToken', token); next(err); });