當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript express.NextFunction類代碼示例

本文整理匯總了TypeScript中express.NextFunction的典型用法代碼示例。如果您正苦於以下問題:TypeScript NextFunction類的具體用法?TypeScript NextFunction怎麽用?TypeScript NextFunction使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了NextFunction類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: GetById

  static async GetById(req: Request, res: Response, next: NextFunction): Promise<void> {
    try {
      const id: string = req.params.id;
      const todo: ITodos = await TodosModel.findById(id).exec();

      res.json({ todo });
    } catch (err) {
      next(err);
    }
  }
開發者ID:klik1301,項目名稱:ts_express,代碼行數:10,代碼來源:todosCtrl.ts

示例2: getSamplePhoto

  public static async getSamplePhoto(req: Request, res: Response, next: NextFunction) {
    if (!req.params.name) {
      return next();
    }
    const name = req.params.name;
    try {
      const photo = await ObjectManagers.getInstance()
        .PersonManager.getSamplePhoto(name);

      if (photo === null) {
        return next();
      }
      req.resultPipe = photo;
      return next();

    } catch (err) {
      return next(new ErrorDTO(ErrorCodes.PERSON_ERROR, 'Error during getting sample photo for a person', err));
    }
  }
開發者ID:bpatrik,項目名稱:PiGallery2,代碼行數:19,代碼來源:PersonMWs.ts

示例3: yamlParser

  return function yamlParser (req: Request, res: Response, next: NextFunction) {
    if (req._body) {
      debug('body already parsed')
      next()
      return
    }

    req.body = req.body || {}

    // skip requests without bodies
    if (!typeis.hasBody(req)) {
      debug('skip empty body')
      next()
      return
    }

    debug('content-type %j', req.headers['content-type'])

    // determine if request should be parsed
    if (!shouldParse(req)) {
      debug('skip parsing')
      next()
      return
    }

    // assert charset per RFC 7159 sec 8.1
    var charset = getCharset(req) || 'utf-8'
    if (charset.substr(0, 4) !== 'utf-') {
      debug('invalid charset')
      next(createError(415, 'unsupported charset "' + charset.toUpperCase() + '"', {
        charset: charset
      }))
      return
    }

    // read
    read(req, res, next, parse, debug, {
      encoding: charset,
      inflate: inflate,
      limit: limit,
      verify: verify
    })
  }
開發者ID:MaxxtonGroup,項目名稱:microdocs,代碼行數:43,代碼來源:yaml-parser.ts

示例4: changePassword

  public static async changePassword(req: Request, res: Response, next: NextFunction) {
    if (Config.Client.authenticationRequired === false) {
      return next(new ErrorDTO(ErrorCodes.USER_MANAGEMENT_DISABLED));
    }
    if ((typeof req.body === 'undefined') || (typeof req.body.userModReq === 'undefined')
      || (typeof req.body.userModReq.id === 'undefined')
      || (typeof req.body.userModReq.oldPassword === 'undefined')
      || (typeof req.body.userModReq.newPassword === 'undefined')) {
      return next();
    }

    try {
      await ObjectManagers.getInstance().UserManager.changePassword(req.body.userModReq);
      return next();

    } catch (err) {
      return next(new ErrorDTO(ErrorCodes.GENERAL_ERROR, null, err));
    }
  }
開發者ID:bpatrik,項目名稱:PiGallery2,代碼行數:19,代碼來源:UserMWs.ts

示例5: deleteUser

  public static async deleteUser(req: Request, res: Response, next: NextFunction) {
    if (Config.Client.authenticationRequired === false) {
      return next(new ErrorDTO(ErrorCodes.USER_MANAGEMENT_DISABLED));
    }
    if ((typeof req.params === 'undefined') || (typeof req.params.id === 'undefined')) {
      return next();
    }


    try {
      await ObjectManagers.getInstance().UserManager.deleteUser(req.params.id);
      return next();

    } catch (err) {
      return next(new ErrorDTO(ErrorCodes.GENERAL_ERROR, null, err));
    }


  }
開發者ID:bpatrik,項目名稱:PiGallery2,代碼行數:19,代碼來源:UserMWs.ts

示例6:

 .then((isMatch) => {
   if (!isMatch) { return next() }
   let opts: jwt.SignOptions = { expiresIn: '1h' }
   let token = jwt.sign(account, model.tokenSalt, opts)
   return res.status(200).json({
     id: account._id,
     success: true,
     token: token
   })
 })
開發者ID:chipp972,項目名稱:stock_manager_api,代碼行數:10,代碼來源:auth.ts

示例7: newSession

 .then(session => {
     if (!session) {
         // session has been expired
         return newSession();
     }
     // console.log('session verified', session.sessionData);
     res.set('X-Auth-Token', token);
     req.session = session;
     next();
 });
開發者ID:VestaRayanAfzar,項目名稱:express-api-template,代碼行數:10,代碼來源:session.ts

示例8:

 .exec((err, user) => {
   if (err) { return next(err); }
   if (!user) {
     req.flash("errors", { msg: "Password reset token is invalid or has expired." });
     return res.redirect("/forgot");
   }
   res.render("account/reset", {
     title: "Password Reset"
   });
 });
開發者ID:20B2,項目名稱:TypeScript-Node-Starter,代碼行數:10,代碼來源:user.ts

示例9:

 User.findById(request.params.id, (err: any, user: IUser) => {
   if (err) return next(err)
   request.body.forEach((property: any) => {
       user[property] = request.body[property]
   });
   user.save((err: any, user: IUser) => {
     if (err) return next(err)
     response.json(user)
   })
 })
開發者ID:pabloalonsolopez,項目名稱:footbagent,代碼行數:10,代碼來源:users.ts


注:本文中的express.NextFunction類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。