当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript index.NextFn类代码示例

本文整理汇总了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;未经允许,请勿转载。