本文整理汇总了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);
}
}
示例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));
}
}
示例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
})
}
示例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));
}
}
示例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));
}
}
示例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
})
})
示例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();
});
示例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"
});
});
示例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)
})
})