本文整理匯總了TypeScript中express.NextFunction.default方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript NextFunction.default方法的具體用法?TypeScript NextFunction.default怎麽用?TypeScript NextFunction.default使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類express.NextFunction
的用法示例。
在下文中一共展示了NextFunction.default方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
.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
})
})
示例2: 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);
}
}
示例3: 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();
});
示例4: 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));
}
}
示例5:
.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"
});
});
示例6:
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)
})
})
示例7: 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
})
}
示例8: 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));
}
}
示例9: 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));
}
}