Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context gets lost in promise when deployed as a serverless app #134

Open
rajasekhar911 opened this issue Jun 1, 2018 · 2 comments
Open

Comments

@rajasekhar911
Copy link

rajasekhar911 commented Jun 1, 2018

I have a NodeJS application using Node8 and Express 4. Am using CLS to store an API token at the time of login and to retrieve the token further down the line. This token is in session and is set to CLS on every request (so that I dont have to pass the request object to each and every method) so that I can retrieve it at a later time in the nth function.

app.use(function(req, res, next) {
  var getNamespace = require('continuation-local-storage').getNamespace,
  authSession = getNamespace('authSession');
  var token = "";
  if(req.session && req.session.auth){
    token = req.session.auth.token;
  }
  authSession.bindEmitter(req);
  authSession.bindEmitter(res);

  authSession.run(function() {
    authSession.set('authToken', token);
    next();
  });
});

This is working fine as a node js app. But when I try to run it as a serverless app, the context does not seem to be set properly. Am using serverless-http package.

I tried to put the patch mentioned in issue 116 ( [https://github.com//issues/116] ). But the interesting part is context.res is undefined in the finally block.

How can I proceed fixing this?

@patran
Copy link

patran commented Jul 12, 2019

Did you find a way forward?

@rajasekhar911
Copy link
Author

check out this commit..
rajasekhar911@ca6fede

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants