mirror of
https://github.com/bitinflow/expose.git
synced 2026-03-13 21:45:55 +00:00
Added custom server host ability
This commit is contained in:
@@ -40,12 +40,12 @@ class Client
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
public function share(string $sharedUrl, array $subdomains = [])
|
||||
public function share(string $sharedUrl, array $subdomains = [], $serverHost = null)
|
||||
{
|
||||
$sharedUrl = $this->prepareSharedUrl($sharedUrl);
|
||||
|
||||
foreach ($subdomains as $subdomain) {
|
||||
$this->connectToServer($sharedUrl, $subdomain, $this->configuration->auth());
|
||||
$this->connectToServer($sharedUrl, $subdomain, $serverHost, $this->configuration->auth());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ class Client
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function connectToServer(string $sharedUrl, $subdomain, $authToken = ''): PromiseInterface
|
||||
public function connectToServer(string $sharedUrl, $subdomain, $serverHost = null, $authToken = ''): PromiseInterface
|
||||
{
|
||||
$deferred = new Deferred();
|
||||
$promise = $deferred->promise();
|
||||
@@ -82,18 +82,18 @@ class Client
|
||||
connect($wsProtocol."://{$this->configuration->host()}:{$this->configuration->port()}/expose/control?authToken={$authToken}", [], [
|
||||
'X-Expose-Control' => 'enabled',
|
||||
], $this->loop)
|
||||
->then(function (WebSocket $clientConnection) use ($sharedUrl, $subdomain, $deferred, $authToken) {
|
||||
->then(function (WebSocket $clientConnection) use ($sharedUrl, $subdomain, $serverHost, $deferred, $authToken) {
|
||||
$this->connectionRetries = 0;
|
||||
|
||||
$connection = ControlConnection::create($clientConnection);
|
||||
|
||||
$connection->authenticate($sharedUrl, $subdomain);
|
||||
$connection->authenticate($sharedUrl, $subdomain, $serverHost);
|
||||
|
||||
$clientConnection->on('close', function () use ($sharedUrl, $subdomain, $authToken) {
|
||||
$clientConnection->on('close', function () use ($sharedUrl, $subdomain, $serverHost, $authToken) {
|
||||
$this->logger->error('Connection to server closed.');
|
||||
|
||||
$this->retryConnectionOrExit(function () use ($sharedUrl, $subdomain, $authToken) {
|
||||
$this->connectToServer($sharedUrl, $subdomain, $authToken);
|
||||
$this->retryConnectionOrExit(function () use ($sharedUrl, $subdomain, $serverHost, $authToken) {
|
||||
$this->connectToServer($sharedUrl, $subdomain, $serverHost, $authToken);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -107,7 +107,7 @@ class Client
|
||||
|
||||
$connection->on('authenticated', function ($data) use ($deferred, $sharedUrl) {
|
||||
$httpProtocol = $this->configuration->port() === 443 ? 'https' : 'http';
|
||||
$host = $this->configuration->host();
|
||||
$host = $data->server_host;
|
||||
|
||||
if ($httpProtocol !== 'https') {
|
||||
$host .= ":{$this->configuration->port()}";
|
||||
@@ -119,7 +119,7 @@ class Client
|
||||
$this->logger->info("Expose-URL:\t\t{$httpProtocol}://{$data->subdomain}.{$host}");
|
||||
$this->logger->line('');
|
||||
|
||||
static::$subdomains[] = "{$httpProtocol}://{$data->subdomain}.{$host}";
|
||||
static::$subdomains[] = "{$httpProtocol}://{$data->subdomain}.{$data->server_host}";
|
||||
|
||||
$deferred->resolve($data);
|
||||
});
|
||||
|
||||
@@ -57,13 +57,14 @@ class ControlConnection
|
||||
$this->proxyManager->createTcpProxy($this->clientId, $data);
|
||||
}
|
||||
|
||||
public function authenticate(string $sharedHost, string $subdomain)
|
||||
public function authenticate(string $sharedHost, string $subdomain, $serverHost = null)
|
||||
{
|
||||
$this->socket->send(json_encode([
|
||||
'event' => 'authenticate',
|
||||
'data' => [
|
||||
'type' => 'http',
|
||||
'host' => $sharedHost,
|
||||
'server_host' => $serverHost,
|
||||
'subdomain' => empty($subdomain) ? null : $subdomain,
|
||||
],
|
||||
]));
|
||||
|
||||
@@ -106,9 +106,9 @@ class Factory
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function share($sharedUrl, $subdomain = null)
|
||||
public function share($sharedUrl, $subdomain = null, $serverHost = null)
|
||||
{
|
||||
app('expose.client')->share($sharedUrl, $subdomain);
|
||||
app('expose.client')->share($sharedUrl, $subdomain, $serverHost);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -120,11 +120,11 @@ class Factory
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function shareFolder(string $folder, string $name, $subdomain = null)
|
||||
public function shareFolder(string $folder, string $name, $subdomain = null, $serverHost = null)
|
||||
{
|
||||
$host = $this->createFileServer($folder, $name);
|
||||
|
||||
$this->share($host, $subdomain);
|
||||
$this->share($host, $subdomain, $serverHost);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user