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

TypeScript hapi.ResponseToolkit类代码示例

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

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



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

示例1: async

      handler: async (request: Request, h: ResponseToolkit) => {
        try {
          const { method } = request;
          const query =
            method === 'post'
              ? (request.payload as Record<string, any>)
              : (request.query as Record<string, any>);

          const graphQLResponse = await runHttpQuery([request], {
            method: method.toUpperCase(),
            options: options.graphQLOptions,
            query,
          });

          return h.response(graphQLResponse).type('application/json');
        } catch (error) {
          if (error.isGraphQLError === true) {
            return h
              .response(error.message)
              .code(error.statusCode)
              .type('application/json');
          }
          return h.response(error).type('application/json');
        }
      },
开发者ID:liuyepiaoxiang,项目名称:kibana,代码行数:25,代码来源:apollo_framework_adapter.ts


示例2: interceptAuth

  return async function interceptAuth(
    req: Request,
    h: ResponseToolkit
  ): Promise<Lifecycle.ReturnValue> {
    try {
      const result = await fn(req, sessionStorage.asScoped(req), toolkit);

      if (AuthResult.isValidResult(result)) {
        if (result.isAuthenticated()) {
          return h.authenticated({ credentials: result.payload });
        }
        if (result.isRedirected()) {
          return h.redirect(result.payload).takeover();
        }
        if (result.isRejected()) {
          const { error, statusCode } = result.payload;
          return Boom.boomify(error, { statusCode });
        }
      }
      throw new Error(
        `Unexpected result from Authenticate. Expected AuthResult, but given: ${result}.`
      );
    } catch (error) {
      return Boom.internal(error.message, { statusCode: 500 });
    }
  };
开发者ID:elastic,项目名称:kibana,代码行数:26,代码来源:auth.ts


示例3: interceptRequest

  return async function interceptRequest(
    req: Request,
    h: ResponseToolkit
  ): Promise<Lifecycle.ReturnValue> {
    try {
      const result = await fn(KibanaRequest.from(req, undefined), toolkit);
      if (OnRequestResult.isValidResult(result)) {
        if (result.isNext()) {
          return h.continue;
        }
        if (result.isRedirected()) {
          return h.redirect(result.payload).takeover();
        }
        if (result.isRejected()) {
          const { error, statusCode } = result.payload;
          return Boom.boomify(error, { statusCode });
        }
      }

      throw new Error(
        `Unexpected result from OnRequest. Expected OnRequestResult, but given: ${result}.`
      );
    } catch (error) {
      return Boom.internal(error.message, { statusCode: 500 });
    }
  };
开发者ID:horacimacias,项目名称:kibana,代码行数:26,代码来源:on_request.ts


示例4:

 const handler = (request: Request, h: ResponseToolkit) => {
     const context = {
         title: 'Views Example',
         message: 'Hello, World',
     };
     return h.view('hello', context);
 };
开发者ID:Dru89,项目名称:DefinitelyTyped,代码行数:7,代码来源:vision-tests.ts


示例5: interceptRequest

  return async function interceptRequest(
    request: Request,
    h: ResponseToolkit
  ): Promise<Lifecycle.ReturnValue> {
    try {
      const result = await fn(KibanaRequest.from(request, undefined), {
        next: OnRequestResult.next,
        redirected: OnRequestResult.redirected,
        rejected: OnRequestResult.rejected,
        setUrl: (newUrl: string | Url) => {
          request.setUrl(newUrl);
          // We should update raw request as well since it can be proxied to the old platform
          request.raw.req.url = typeof newUrl === 'string' ? newUrl : newUrl.href;
        },
      });
      if (OnRequestResult.isValidResult(result)) {
        if (result.isNext()) {
          return h.continue;
        }
        if (result.isRedirected()) {
          return h.redirect(result.payload).takeover();
        }
        if (result.isRejected()) {
          const { error, statusCode } = result.payload;
          return Boom.boomify(error, { statusCode });
        }
      }

      throw new Error(
        `Unexpected result from OnRequest. Expected OnRequestResult, but given: ${result}.`
      );
    } catch (error) {
      return Boom.internal(error.message, { statusCode: 500 });
    }
  };
开发者ID:elastic,项目名称:kibana,代码行数:35,代码来源:on_request.ts


示例6:

 authenticate: (request: Request, h: ResponseToolkit) => {
     const authorization = request.headers.authorization;
     if (!authorization) {
         throw Boom.unauthorized(null, 'Custom');
     }
     return h.authenticated({ credentials: { user: 'john' } });
 }
开发者ID:dvine-multimedia,项目名称:DefinitelyTyped,代码行数:7,代码来源:server-auth-api.ts


示例7: async

      handler: async (request: Request, h: ResponseToolkit) => {
        try {
          const query =
            request.method === 'post'
              ? (request.payload as Record<string, any>) // eslint-disable-line @typescript-eslint/no-explicit-any
              : (request.query as Record<string, any>); // eslint-disable-line @typescript-eslint/no-explicit-any

          const gqlResponse = await runHttpQuery([request], {
            method: request.method.toUpperCase(),
            options: options.graphqlOptions,
            query,
          });

          return h.response(gqlResponse).type('application/json');
        } catch (error) {
          if ('HttpQueryError' !== error.name) {
            const queryError = Boom.boomify(error);

            queryError.output.payload.message = error.message;

            return queryError;
          }

          if (error.isGraphQLError === true) {
            return h
              .response(error.message)
              .code(error.statusCode)
              .type('application/json');
          }

          const genericError = new Boom(error.message, { statusCode: error.statusCode });

          if (error.headers) {
            Object.keys(error.headers).forEach(header => {
              genericError.output.headers[header] = error.headers[header];
            });
          }

          // Boom hides the error when status code is 500

          genericError.output.payload.message = error.message;

          throw genericError;
        }
      },
开发者ID:,项目名称:,代码行数:45,代码来源:


示例8: formatUrl

 this.server.ext('onRequest', (request: Request, responseToolkit: ResponseToolkit) => {
   return responseToolkit
     .redirect(
       formatUrl({
         hostname: config.host,
         pathname: request.url.pathname,
         port: config.port,
         protocol: 'https',
         search: request.url.search,
       })
     )
     .takeover();
 });
开发者ID:austec-automation,项目名称:kibana,代码行数:13,代码来源:https_redirect_server.ts


示例9: handler

  async function handler(exportTypeId: any, jobParams: any, request: Request, h: ResponseToolkit) {
    // @ts-ignore
    const user = request.pre.user;
    const headers = request.headers;

    const job = await enqueueJob(exportTypeId, jobParams, user, headers, request);

    // return the queue's job information
    const jobJson = job.toJSON();

    return h
      .response({
        path: `${DOWNLOAD_BASE_URL}/${jobJson.id}`,
        job: jobJson,
      })
      .type('application/json');
  }
开发者ID:elastic,项目名称:kibana,代码行数:17,代码来源:index.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript hapi.Server类代码示例发布时间:2022-05-25
下一篇:
TypeScript hapi.Request类代码示例发布时间: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