本文整理汇总了TypeScript中express-serve-static-core.NextFunction.default方法的典型用法代码示例。如果您正苦于以下问题:TypeScript NextFunction.default方法的具体用法?TypeScript NextFunction.default怎么用?TypeScript NextFunction.default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类express-serve-static-core.NextFunction
的用法示例。
在下文中一共展示了NextFunction.default方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: next
app.use(function(req: Request, res: Response, next: NextFunction) {
// Remove trailing slash
if (req.path.substr(-1) === "/" && req.path.length > 1) {
let query = req.url.slice(req.path.length);
res.redirect(HttpStatus.MOVED_PERMANENTLY, req.path.slice(0, -1) + query);
} else {
next();
}
});
示例2: function
function (err, province) {
if (err) return errorHandler.handleError(res, err);
if (!province) {
return errorHandler.sendError(res, errorHandler.ERROR_NOT_FOUND, "No se encuentra la provincia " + req.body.province);
}
req.province = province;
next();
});
示例3: logErrors
export function logErrors(err: any, req: express.Request, res: express.Response, next: NextFunction) {
if (!err) return next();
console.error(err.message);
res.status(err.status || ERROR_INTERNAL_ERROR);
res.json({
error: err.message
});
}
示例4: APIError
this.app.use( ( req: Request, res: Response, next: NextFunction ) => {
let errParams: APIErrorParams = {
url: req.baseUrl + req.url,
method: req.method,
status: 404,
message: 'Not Found: it may be a bad URL or bad method',
env: this.app.get( 'env' )
};
let err: any = new APIError( errParams );
next( err );
} );
示例5: function
redisClient.get(escape(id), function (err, reply) {
if (err) return errorHandler.handleError(res, err);
if (!reply) {
return errorHandler.sendError(res, errorHandler.ERROR_NOT_FOUND, "No se pudo cargar la imagen " + id);
}
req.image = {
id: escape(id),
image: reply
};
next();
});
示例6: fillProvinceIfPresent
export function fillProvinceIfPresent(req: IFindProvince, res: express.Response, next: NextFunction) {
// Si no viene ninguna provincia definida, no hacemos nada
if (!req.body.province) {
return next();
}
Province.findOne({
_id: escape(req.body.province),
enabled: true
},
function (err, province) {
if (err) return errorHandler.handleError(res, err);
if (!province) {
return errorHandler.sendError(res, errorHandler.ERROR_NOT_FOUND, "No se encuentra la provincia " + req.body.province);
}
req.province = province;
next();
});
}
示例7:
Post.deleteOne({_id: mongoose.Types.ObjectId(req.params.postid) }).exec(function(error, post) {
if (error) return next();
return res.json(post);
});
示例8: next
req.getValidationResult().then(function (result) {
if (!result.isEmpty()) {
return errorHandler.handleExpressValidationError(res, result);
}
next();
});