Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var router = require('express').Router();
- var mongoose = require('mongoose');
- var User = mongoose.model('User');
- var auth = require('../auth');
- // if the route contains the username path parameter, fetch the user's profile
- router.param('username', function(req, res, next, username) {
- // find the user with the username from the path
- User.findOne({username: username}).then(function(user){
- if (!user) { return res.sendStatus(404); }
- req.profile = user;
- return next();
- }).catch(next);
- });
- router.get('/:username', auth.optional, function(req, res, next) {
- return res.json({profile: req.profile.toProfileJSONFor()});
- });
- module.exports = router;
Advertisement
Add Comment
Please, Sign In to add comment