From 7aa1225e31f0eb8adec3df2dfb0cb7ef7cc08b6a Mon Sep 17 00:00:00 2001 From: Marcel Pociot Date: Mon, 4 May 2020 16:34:41 +0200 Subject: [PATCH] wip --- app/Client/Client.php | 4 +-- app/Client/Factory.php | 13 +++++++- .../Controllers/CreateTunnelController.php | 33 +++++++++++++++++++ resources/views/client/dashboard.twig | 2 +- 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 app/Client/Http/Controllers/CreateTunnelController.php diff --git a/app/Client/Client.php b/app/Client/Client.php index b509911..6af4e88 100644 --- a/app/Client/Client.php +++ b/app/Client/Client.php @@ -126,9 +126,9 @@ class Client $this->logger->info($data->message); $this->logger->info("Connected to {$httpProtocol}://{$data->subdomain}.{$host}"); - static::$subdomains[] = "$data->subdomain.{$this->configuration->host()}:{$this->configuration->port()}"; + static::$subdomains[] = "{$httpProtocol}://{$data->subdomain}.{$host}"; - $deferred->resolve(); + $deferred->resolve($data); }); }, function (\Exception $e) use ($deferred, $sharedUrl, $subdomain, $authToken) { diff --git a/app/Client/Factory.php b/app/Client/Factory.php index 17a397d..8ba960a 100644 --- a/app/Client/Factory.php +++ b/app/Client/Factory.php @@ -2,6 +2,7 @@ namespace App\Client; +use App\Client\Http\Controllers\CreateTunnelController; use App\Client\Http\Controllers\PushLogsToDashboardController; use App\Client\Http\HttpClient; use App\Http\App; @@ -79,6 +80,13 @@ class Factory }); } + protected function bindClient() + { + app()->singleton('expose.client', function ($app) { + return $app->make(Client::class); + }); + } + protected function bindProxyManager() { app()->bind(ProxyManager::class, function ($app) { @@ -88,6 +96,8 @@ class Factory public function createClient() { + $this->bindClient(); + $this->bindConfiguration(); $this->bindProxyManager(); @@ -97,7 +107,7 @@ class Factory public function share($sharedUrl, $subdomain = null) { - app(Client::class)->share($sharedUrl, $subdomain); + app('expose.client')->share($sharedUrl, $subdomain); return $this; } @@ -105,6 +115,7 @@ class Factory protected function addRoutes() { $this->router->get('/', DashboardController::class); + $this->router->post('/tunnel', CreateTunnelController::class); $this->router->get('/logs', LogController::class); $this->router->post('/logs', PushLogsToDashboardController::class); $this->router->get('/replay/{log}', ReplayLogController::class); diff --git a/app/Client/Http/Controllers/CreateTunnelController.php b/app/Client/Http/Controllers/CreateTunnelController.php new file mode 100644 index 0000000..7b0b651 --- /dev/null +++ b/app/Client/Http/Controllers/CreateTunnelController.php @@ -0,0 +1,33 @@ +connectToServer($request->get('url'), $request->get('subdomain', ''), config('expose.auth_token')) + ->then(function ($data) use ($httpConnection) { + $httpConnection->send(respond_json($data)); + $httpConnection->close(); + }, function() use ($httpConnection) { + $httpConnection->send(str(new Response(500))); + $httpConnection->close(); + }); + + } +} diff --git a/resources/views/client/dashboard.twig b/resources/views/client/dashboard.twig index 0566a4a..8847346 100644 --- a/resources/views/client/dashboard.twig +++ b/resources/views/client/dashboard.twig @@ -93,7 +93,7 @@

Waiting for requests on: {% for subdomain in subdomains %} - {{ subdomain }} + {{ subdomain }} {% endfor %}