i am trying to implement middle ware function in my express js application it follows a simple MVC architecture.
routes.js
under route
folder
//load the controller auth.js
var auth = require('../controllers/auth');
//auth route
router.route('/auth').get(auth.simpleAuth);
auth.js
under controllers
folder
//load the middleware
var middleware = require('../middleware/middleware');
module.exports={
simpleAuth:function (req,res) {
//invoke middleware
middleware.testMiddleware;
res.send('middleware test completed');
}
}
middleware.js
under middleware
folder
module.exports={
testMiddleware:function (req,res,next) {
console.log('inside middleware');
if(req.username == true){
next();
}else{
console.log('auth failed')
}
}
}
There is no error message is shown but when i access auth
route the middle ware function is not invoked.
via Jabaa
No comments:
Post a Comment