I'm trying to write a wrapper function around expressjs's app.get
The get (and other methods) accept as arguments, the path, some options, then the callback. But sometimes you can leave the options out and still work.
I used to do:
app.get(path, auth.loadUser, function () {
// example
})
so this doesn't work:
custom.get = function (path, callback) {
// ?? missing a spot in the arguments array
app.get(path, auth.loadUser, function () {
// example
})
}
I need to be able to do this:
custom.get (path, callback) {
}
and this:
custom.get (path, auth.loadUser, callback) {
}
and have them both work at the same time, like in express.
So how can I write a wrapper function that knows that the first arg is the path and the last arg is the callback and everything else in the middle is optional?