Reputation: 526
var authenticate = require('../authenticate');
const dishRouter = express.Router();
dishRouter.use(bodyParser.json());
dishRouter.route('/')
.get((req,res,next) => {
Dishes.find({})
.then((dishes) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'application/json');
res.json(dishes);
}, (err) => next(err))
.catch((err) => next(err));
})
.post(authenticate.verifyUser, (req, res, next) => {
Dishes.create(req.body)
.then((dish) => {
console.log('Dish Created ', dish);
res.statusCode = 200;
res.setHeader('Content-Type', 'application/json');
res.json(dish);
}, (err) => next(err))
.catch((err) => next(err));
})
Getting error at .post() function. I'm using authenticate.verifyUser to authenticate the user using Passport-jwt.Error
Upvotes: 1
Views: 45
Reputation: 526
Solved! It was just a version issue. After updating the express it worked!
Upvotes: 1