当前位置: 首页>>代码示例>>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;未经允许,请勿转载。