supermasher
supermasher

Reputation: 742

Pass a route segment as callback argument

I'm building my first app in express. Is it possible to somehow pass a route segment as an argument to a callback?

app.get('/connect/:mySegment', myCallback(mySegment));

Specifically, I'm using passport with several strategies for authentication. So rather than doing,

app.get('/connect/twitter',
  passport.authorize('twitter')
);
app.get('/connect/facebook',
  passport.authorize('facebook')
);

I would like to do something along the lines of...

app.get('/connect/:service', passport.authorize(service));

Upvotes: 0

Views: 61

Answers (1)

zs2020
zs2020

Reputation: 54543

Of course, you can do

app.get('/connect/:mySegment', function(req, res){
    // then you can use req.params.mySegment
});

Upvotes: 1

Related Questions