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

Adding multiple router handlers #1183

Closed
jcald1 opened this issue Sep 13, 2016 · 3 comments
Closed

Adding multiple router handlers #1183

jcald1 opened this issue Sep 13, 2016 · 3 comments
Labels

Comments

@jcald1
Copy link

jcald1 commented Sep 13, 2016

I'm trying to add multiple router handlers like so:

var handlers = []
for (var i = 0; i < config.length; i++) {
   var func = = function(req, res, next) {
                                  ....
            };
   handlers.push(func);
}
app.get(oneRouteConfig.context, handlers);

However, only the last handler is executed. I tried to add them as two separate parameters instead of an array, and I had the same result. I also tried using the new keyword and had the same results. I can only seem to get multiple handlers to execute when I actually write out the different handlers manually.

@micahr
Copy link
Member

micahr commented Sep 13, 2016

Try the following:

app.get.apply(app, handlers)

The http method based route registration function takes a variable amount of functions to run, but not an array of functions. So calling apply will fix that.

@jcald1
Copy link
Author

jcald1 commented Sep 19, 2016

I ended up just manually adding them, but I suggest updating the API documentation is apply() is the preferred way to dynamically anonymous functions multiple times, or functions instantiated with new.

@yunong yunong added the Docs label Jan 9, 2017
@yunong
Copy link
Member

yunong commented Jan 9, 2017

We'll add this to the documentation backlog for the next release.

retrohacker pushed a commit that referenced this issue Apr 29, 2017
Closes:

#289
#381
#474
#575
#790
#633
#717
#576
#576
#909
#875
#860
#853
#850
#829
#813
#801
#921
#1101
#1019
#989
#632
#708
#737
#859
#1326
#1327
#927
#1099
#1068
#1040
#1035
#957
#948
#1134
#1136
#1183
#1206
#1286
#1323

> Note: this issue closes _but does not resolve_ the issues listed, we are just tracking them in another medium
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants