Resolve promise before registering middleware and exposing routes
See original GitHub issueI 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:
- Created 3 years ago
- Comments:8
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Will definitely do by end of this week.
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.