question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Resolve promise before registering middleware and exposing routes

See original GitHub issue

I need to fetch a secret from a secrets manager using an async request to use for my middleware, but I find that I get no response or a timed out one when I try and wrap my middleware and routes in a promise chain.

getSecret().then(secret => {
  const strategy = new OAuth2Strategy({
    secret: secret
  }, function (accessToken, refreshToken, params, profile, done) {
    done(null,{data: 'some user data'});
  })


  passport.use('oauth2', strategy);
  refresh.use('oauth2', strategy);

  app.get('/my_route', async function (req, res) {
    ...
  })
})

What is the best way to deal with async code that needs to be resolved before I expose my routes?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
saachinsivacommented, Feb 2, 2021

Please see https://github.com/vendia/serverless-express/blob/mainline/UPGRADE.md for info on upgrading. I haven’t tested with Nest. Let me know if you hit any issues. If you could send a PR with a minimum Nest example, that’d be great!

Will definitely do by end of this week.

1reaction
brettstackcommented, Jan 27, 2021

Sorry, that should be return serverlessExpressHandler(event, context). I don’t have any complete examples though I recall seeing some Issues here with comments doing similar things. Definitely a common/valid use case that I should add an example for.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolve promise using Node/Express before registering ...
1 Answer 1 · define an async function which helps in awaiting other infrastructure configs/data · load all necessary configs · create express...
Read more >
Using Express.js Routes for Promise-based Error Handling
Find out how to enable promise-based route code and centralize both error ... Here we create an Express.js app and add some basic...
Read more >
Using promises | LoopBack Documentation
When a successful promise is fulfilled, all of the pending callbacks are called with the value. If more callbacks are registered in the...
Read more >
Getting route data in your ASP.NET Core middleware - RIMdev
-wide, exposed routing system increased. The 🗝️ to making this work. ASP.NET Core 2.2. using Microsoft.AspNetCore.Internal ...
Read more >
Express/Node introduction - Learn web development | MDN
This object, which is traditionally named app , has methods for routing HTTP requests, configuring middleware, rendering HTML views, registering ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found