Define TLS encryption settings for this host
public encrypt ( string $certificate, string $key = null, array $options = [] ) : |
||
$certificate | string | A string path pointing to your SSL/TLS certificate |
$key | string | A string path pointing to your SSL/TLS key file (null if the certificate file is containing the key already) |
$options | array | An optional array mapping additional SSL/TLS settings |
return |
$sslEnabled = false; if ($config['web-api']['ssl']['enable']) { if (!isset($config['web-api']['ssl']['cert-path'])) { throw new InvalidConfigurationException('SSL-enabled web API must define a certificate path'); } $sslEnabled = true; $sslCert = realpath($config['web-api']['ssl']['cert-path']); if (!$sslCert) { throw new InvalidConfigurationException('Invalid SSL certificate path'); } $sslKey = null; if (isset($config['web-api']['ssl']['key-path']) && !($sslKey = realpath($config['web-api']['ssl']['key-path']))) { throw new InvalidConfigurationException('Invalid SSL key path'); } $sslContext = $config['web-api']['ssl']['context'] ?? []; $host->encrypt($sslCert, $sslKey, $sslContext); } $bindAddr = $config['web-api']['bind-addr'] ?? '127.0.0.1'; $bindPort = (int) ($config['web-api']['bind-port'] ?? ($sslEnabled ? 1337 : 1338)); $host->expose($bindAddr, $bindPort); if (isset($config['web-api']['host'])) { $host->name($config['web-api']['host']); } /** @var WebAPIServer $api */ $api = $injector->make(WebAPIServer::class); $host->use($api->getRouter()); (new Bootstrapper(function () use($host) { return [$host]; }))->init(new AerysLogger($injector->make(Logger::class)))->start(); } onError(function (\Throwable $e) {