// SPECIFIC DISH dishRouter.route('/:dishId') .all(function(req, res, next){ res.writeHead(200, {'Content-Type': 'text-plain'}); next(); }) .get(function(req, res, next){ res.end('You want info for the dish '+ req.params.dishId); }) .put(function(req, res, next){ res.end('you want to update '+ req.params.dishId + ' with ' + req.body.name + ' '+ req.body.name); });
/** * Route for Permissions */ router.route('*') .all((request, response, next) => { response.header('Access-Control-Allow-Origin', '*') response.header('Access-Control-Allow-Headers', 'Content-Type,Authorization,Cache-Control,Accept,Accept-Encoding') next() })
leaderRouter.route('/:leaderId') .all(function(req, res, next){ res.writeHead(200, {'Content-type': 'text-plain'}); next(); }) .get(function(req, res){ res.end('Get attributes for ' + req.params.leaderId); }) .put(function(req, res){ res.end('KSJdl' + req.body.name); }) .delete(function(req, res){ res.end('Delete leader with id ' + req.params.leaderId); });
router.route("/login/") .all(authMiddleware.logoutRequired) .get(function(request, response) { return response.render("auth/login"); }) .post( passport.authenticate("local", {failureRedirect: "/login/"}), function(request, response) { return response.redirect("/"); } );
apiRouter.route('/:apiName') .all(function (req, res) { fs.readFile('./db.json', 'utf8', function (err, data) { if (err) throw err var data = JSON.parse(data) if (data[req.params.apiName]) { res.json(data[req.params.apiName]) } else { res.send('no such api name') } }) })
/*------------------------------------------------------ route.all is extremely useful. you can use it to do stuffs for specific routes. for example you need to do a validation everytime route /api/user/:user_id it hit. remove curut2.all() if you dont want it ------------------------------------------------------*/ curut2.all(function(req,res,next){ console.log("You need to smth about curut2 Route ? Do it here"); console.log(req.params); next(); });
leaderRouter.route('/') .all(function(req, res, next){ res.writeHead(200, {'Content-type':'text-plain'}); next(); }) .get(function(req, res){ res.end('Return all leaders'); }) .post(function(req, res){ res.end('Post new leader '+ req.body.name); }) .delete(function(req, res){ res.end('Delete evertyhin'); });
router.route('/').all((req, res) => { return res.status(404).json({code: 404, name: 'NotFound', message: 'Not found'}); });
router.route("/:dishId") .all(function(req, res, next){ res.writeHead(200, {"Content-Type":"text/plain"}); next(); }) .get(function(req, res, next){ res.end("Dish with id "+req.params.dishId+" will be listed"); }) .put(function(req, res, next){ res.end("dish with dish id "+req.params.dishId+" will be updated with name "+req.body.name+" and desc "+req.body.description); }) .delete(function(req, res, next){ res.end("dish with id "+req.params.dishId+" will be deleted"); });
router.route("/") .all(function(req, res, next){ res.writeHead(200, {"Content-Type":"text/plain"}); next(); }) .get(function(req, res, next){ res.end("All dishes will be listed"); }) .post(function(req, res, next){ res.end("New dish will be created with name "+req.body.name+" and desc "+req.body.description); }) .delete(function(req, res, next){ res.end("Delete all dishes"); })
// SPECIFIC DISH dishRouter.route('/:dishId') .all(function(req, res, next){ res.writeHead(200, {'Content-Type': 'text-plain'}); next(); }) .get(function(req, res, next){ res.end('You want info for the dish '+ req.params.dishId); }) .put(function(req, res, next){ res.end('you want to update '+ req.params.dishId + ' with ' + req.body.name + ' '+ req.body.name); });
// SPECIFIC DISH dishRouter.route('/:dishId') .all(function(req, res, next){ res.writeHead(200, {'Content-Type': 'text-plain'}); next(); }) .get(function(req, res, next){ res.end('You want info for the dish '+ req.params.dishId); }) .put(function(req, res, next){ res.end('you want to update '+ req.params.dishId + ' with ' + req.body.name + ' '+ req.body.name); });
curut2.all(function(req,res,next){ console.log("You need to smth about curut2 Route ? Do it here"); console.log(req.params); next(); });
promoRouter.route('/') .all(function(req, res, next){ res.writeHead(200, {'Content-Type': 'text-plain'}); next(); }) .get(function(req, res, next){ res.end('You will get all Promotions objects'); }) .post(function(req, res, next){ res.end('I will store ' + req.body.name); }) .delete(function(req, res, next){ res.end('I will delete everything'); });
leaderRouter.route('/') .all(function(req,res,next) { res.writeHead(200, { 'Content-Type': 'text/plain' }); next(); }) .get(function(req,res,next){ res.end('Will send all the leaders to you!'); }) .post(function(req, res, next){ res.end('Will add the leader: ' + req.body.name + ' with details: ' + req.body.description); }) .delete(function(req, res, next){ res.end('Deleting all leaders'); });