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


TypeScript ResponseToolkit.redirect方法代码示例

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


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

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

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

示例4: 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

示例5:

 handler: (request: Request, h: ResponseToolkit) => {
     return h.redirect('http://example.com');
 }
开发者ID:dvine-multimedia,项目名称:DefinitelyTyped,代码行数:3,代码来源:redirect.ts


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