1 var findUserByUsernameMiddleware = function (request, response, next) {
2 if (request.params.username) {
3 console.log(‘Username param was detected: ‘ + request.params.username);
4 findUserByUsername(request.params.username, function (error, user) {
5 if (error)return next(error);
6 request.user = user;
7 return next();
8 })
9 } else {
10 return next();
11 }
12 }
13
14 app.get(‘/v2/users/:username‘,
15 findUserByUsernameMiddleware,
16 function (request, response, next) {
17 return response.render(‘user‘, request.user);
18 });
19
20 app.get(‘/v2/admin/:username‘,
21 findUserByUsernameMiddleware,
22 function (request, response, next) {
23 return response.render(‘admin‘, request.user);
24 });