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.

option.router with callback in arguments

See original GitHub issue

Hi, thanks for awesome library. I’m trying to use it as proxy for app but I have to do async actions to resolve new target.

It would be great to have possibility to do something like this:

var apiProxy = proxy('/api', {
  target: 'http://localhost:1234',
  router: function (req, callback) {
     myAsyncApi()
          .then(function(newTarget){
                 callback('newTarget');
          })
  }
});

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:16
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

18reactions
chimuraicommented, Mar 20, 2017

Thank you for the kind words.

Never thought of the be used this way.

Will consider adding it if more users have to need for this.

11reactions
jakubzloczewskicommented, Mar 17, 2017

I can achieve my goal by adding middleware before proxy to do that asynchronous actions before and keep ‘newTarget’ in req object. But still I would be nice to have ‘callback’ in arguments.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to pass arguments to a callback function in express?
1 Answer 1 ; function verification(arg1, arg2, req, res, next) {...} router. ; post · '/item/:id/dosomething', verification.bind( ; post · '/item/:id ...
Read more >
callback-router - npm
Determines which routes match the pathname and invokes their callbacks. Returns the value returned from the callback of the highest-priority ( ...
Read more >
Routing - Express.js
In fact, the routing methods can have more than one callback function as arguments. With multiple callback functions, it is important to provide...
Read more >
Express.js router.param() function - GeeksforGeeks
Basically router.param() function triggers the callback function whenever user routes to the parameter. This callback function will be called ...
Read more >
Express Tutorial Part 4: Routes and controllers - MDN Web Docs
The router function above takes a single callback, but you can specify as many callback arguments as you want, or an array of...
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