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) { fwrite(STDERR, "\nAn exception was not handled:\n\n{$e}\n\n"); }); try { run(); } catch (\Throwable $e) { fwrite(STDERR, "\nSomething went badly wrong:\n\n{$e}\n\n"); }