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


TypeScript Server.ext方法代码示例

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


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

示例1: start

  public async start(config: HttpConfig) {
    if (!config.ssl.enabled || config.ssl.redirectHttpFromPort === undefined) {
      throw new Error(
        'Redirect server cannot be started when [ssl.enabled] is set to `false`' +
          ' or [ssl.redirectHttpFromPort] is not specified.'
      );
    }

    this.log.info(
      `starting HTTP --> HTTPS redirect server [${config.host}:${config.ssl.redirectHttpFromPort}]`
    );

    // Redirect server is configured in the same way as any other HTTP server
    // within the platform with the only exception that it should always be a
    // plain HTTP server, so we just ignore `tls` part of options.
    this.server = createServer({
      ...getServerOptions(config, { configureTLS: false }),
      port: config.ssl.redirectHttpFromPort,
    });

    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();
    });

    try {
      await this.server.start();
    } catch (err) {
      if (err.code === 'EADDRINUSE') {
        throw new Error(
          'The redirect server failed to start up because port ' +
            `${config.ssl.redirectHttpFromPort} is already in use. Ensure the port specified ` +
            'in `server.ssl.redirectHttpFromPort` is available.'
        );
      } else {
        throw err;
      }
    }
  }
开发者ID:Jaaess,项目名称:kibana,代码行数:48,代码来源:https_redirect_server.ts


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