本文整理汇总了TypeScript中hapi-latest.Server.start方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Server.start方法的具体用法?TypeScript Server.start怎么用?TypeScript Server.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hapi-latest.Server
的用法示例。
在下文中一共展示了Server.start方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: start
public async start(options: Readonly<BasePathProxyServerOptions>) {
this.log.debug('starting basepath proxy server');
const serverOptions = getServerOptions(this.httpConfig);
this.server = createServer(serverOptions);
// Register hapi plugin that adds proxying functionality. It can be configured
// through the route configuration object (see { handler: { proxy: ... } }).
await this.server.register({ plugin: require('h2o2-latest') });
if (this.httpConfig.ssl.enabled) {
const tlsOptions = serverOptions.tls as TlsOptions;
this.httpsAgent = new HttpsAgent({
ca: tlsOptions.ca,
cert: tlsOptions.cert,
key: tlsOptions.key,
passphrase: tlsOptions.passphrase,
rejectUnauthorized: false,
});
}
this.setupRoutes(options);
await this.server.start();
this.log.info(
`basepath proxy server running at ${this.server.info.uri}${this.httpConfig.basePath}`
);
}
示例2: 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;
}
}
}