Express Middleware

Intro to Express.js: Parameters, Error Handling and Other Middleware

Đặc điểm của Express là cho phép nỗi chuỗi các middleware xử lý req, res

app.get('/api/v1/stories/:id', function(req,res, next) {
  //do authorization
  //if not authorized or there is an error 
  // return next(error);
  //if authorized and no errors
  return next();
}), function(req,res, next) {
  //extract id and fetch the object from the database
  //assuming no errors, save story in the request object
  req.story = story;
  return next();
}), function(req,res) {
  //output the result of the database search
  res.send(res.story);
});

results matching ""

    No results matching ""