當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript NextFn.default方法代碼示例

本文整理匯總了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();
    });
開發者ID:shmoop207,項目名稱:appolo,代碼行數:11,代碼來源:checkValidationMiddleware.ts

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


}
開發者ID:shmoop207,項目名稱:appolo,代碼行數:30,代碼來源:invokeActionMiddleware.ts

示例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))
    }
}
開發者ID:uditalias,項目名稱:appolo,代碼行數:44,代碼來源:invokeActionMiddleware.ts

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


    }
開發者ID:shmoop207,項目名稱:appolo,代碼行數:22,代碼來源:invokeActionMiddleware.ts

示例5: next

 .catch(e => next(_handleError(e, res)));
開發者ID:uditalias,項目名稱:appolo,代碼行數:1,代碼來源:invokeActionMiddleware.ts

示例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))
    }
}
開發者ID:shmoop207,項目名稱:appolo,代碼行數:63,代碼來源:invokeActionMiddleware.ts

示例7: next

 .catch(e => next(_handleError(e)));
開發者ID:shmoop207,項目名稱:appolo,代碼行數:1,代碼來源:invokeActionMiddleware.ts


注:本文中的appolo-agent/index.NextFn.default方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。