本文整理汇总了TypeScript中appolo-agent/index.NextFn.default方法的典型用法代码示例。如果您正苦于以下问题:TypeScript NextFn.default方法的具体用法?TypeScript NextFn.default怎么用?TypeScript NextFn.default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类appolo-agent/index.NextFn
的用法示例。
在下文中一共展示了NextFn.default方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: next
joi.validate(data, req.route.validations, req.app.options.validatorOptions, function (e, params) {
if (e) {
return next(new BadRequestError(e.toString()));
}
req.model = params;
next();
});
示例2: invokeCustomRouteMiddleWare
export function invokeCustomRouteMiddleWare(req: IRequest, res: IResponse, next: NextFn) {
let route = req.route;
if (route.gzip) {
res.gzip();
}
if (route.headers.length) {
for (let i = 0, len = route.headers.length; i < len; i++) {
let header = route.headers[i];
res.setHeader(header.key, header.value);
}
}
if (route.customRouteFn.length) {
for (let i = 0, len = route.customRouteFn.length; i < len; i++) {
let fn = route.customRouteFn[i];
fn(req, res, req.route)
}
}
if (route.statusCode) {
res.status(route.statusCode);
}
next();
}
示例3: invokeActionMiddleware
export function invokeActionMiddleware(req: IRequest, res: IResponse, next: NextFn) {
let route = req.route;
let controller: StaticController = req.app.injector.getObject<StaticController>(route.controller, [req, res, route]);
if (!controller) {
next(new HttpError(500, `failed to find controller ${route.controller}`));
return;
}
let fnName: string = route.actionName;
if (!fnName) {
fnName = _.isString(route.action) ? route.action : route.action(controller).name;
if (!controller[fnName]) {
next(new HttpError(500, `failed to invoke ${this.constructor.name} fnName ${fnName}`));
return;
}
route.actionName = fnName;
}
try {
let result = controller[fnName](req, res, req.model, route);
if (res.headersSent || res.sending) {
return;
}
if (!result || !(result.then && result.catch)) {
return res.send(result)
}
result
.then(data => (!res.headersSent && !res.sending) && res.send(data))
.catch(e => next(_handleError(e, res)));
} catch (e) {
next(_handleError(e, res))
}
}
示例4: function
return function (req: IRequest, res: IResponse, next: NextFn) {
let middleware: IMiddleware = req.app.injector.getObject<IMiddleware>(middlewareId, [req, res, next, req.route]);
if (!middleware) {
return next(new HttpError(500, `failed to find middleware ${middlewareId}`));
}
let result = middleware.run(req, res, next, req.route);
if (res.headersSent || res.sending || middleware.run.length > 2) {
return;
}
if (!result || !result.then || !result.catch) {
return next();
}
result.then(() => (!res.headersSent && !res.sending) && next())
.catch(e => next(_handleError(e)));
}
示例5: next
.catch(e => next(_handleError(e, res)));
示例6: invokeActionMiddleware
export function invokeActionMiddleware(req: IRequest, res: IResponse, next: NextFn) {
let route = req.route;
let controller: StaticController = req.app.injector.getObject<StaticController>(route.controller, [req, res, route]);
if (!controller) {
next(new HttpError(500, `failed to find controller ${route.controller}`));
return;
}
let fnName: string = route.actionName;
if (!fnName) {
fnName = _.isString(route.action) ? route.action : route.action(controller).name;
if (!controller[fnName]) {
next(new HttpError(500, `failed to invoke ${this.constructor.name} fnName ${fnName}`));
return;
}
route.actionName = fnName;
}
try {
let result;
if (route.customRouteParam.length) {
let args = [req, res, req.model, route];
for (let i = 0, len = route.customRouteParam.length; i < len; i++) {
let data = route.customRouteParam[i];
args.splice(data.index, 0, data.fn(req, res, req.route));
}
result = controller[fnName].apply(controller, args);
} else {
result = controller[fnName](req, res, req.model, route);
}
if (res.headersSent || res.sending) {
return;
}
if (result && result.then && result.catch) {
result
.then(data => (!res.headersSent && !res.sending) && res.send(data))
.catch(e => next(_handleError(e)));
return;
}
res.send(result)
} catch (e) {
next(_handleError(e))
}
}
示例7: next
.catch(e => next(_handleError(e)));