• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript index.NextFn类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中appolo-agent/index.NextFn的典型用法代码示例。如果您正苦于以下问题:TypeScript NextFn类的具体用法?TypeScript NextFn怎么用?TypeScript NextFn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了NextFn类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: 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();


}
开发者ID:shmoop207,项目名称:appolo,代码行数:30,代码来源:invokeActionMiddleware.ts


示例2: 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))
    }
}
开发者ID:uditalias,项目名称:appolo,代码行数:44,代码来源:invokeActionMiddleware.ts


示例3: 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)));


    }
开发者ID:shmoop207,项目名称:appolo,代码行数:22,代码来源:invokeActionMiddleware.ts


示例4: 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))
    }
}
开发者ID:shmoop207,项目名称:appolo,代码行数:63,代码来源:invokeActionMiddleware.ts


示例5: 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();
    });
开发者ID:shmoop207,项目名称:appolo,代码行数:11,代码来源:checkValidationMiddleware.ts


示例6: next

 .catch(e => next(_handleError(e, res)));
开发者ID:uditalias,项目名称:appolo,代码行数:1,代码来源:invokeActionMiddleware.ts


示例7: next

 .catch(e => next(_handleError(e)));
开发者ID:shmoop207,项目名称:appolo,代码行数:1,代码来源:invokeActionMiddleware.ts



注:本文中的appolo-agent/index.NextFn类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript AppState.ThunkResult类代码示例发布时间:2022-05-25
下一篇:
TypeScript appolo-agent.NextFn类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap