This commit is contained in:
Marcel Pociot
2020-05-04 16:34:41 +02:00
parent f8464d2b4d
commit 7aa1225e31
4 changed files with 48 additions and 4 deletions

View File

@@ -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) {

View File

@@ -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);

View File

@@ -0,0 +1,33 @@
<?php
namespace App\Client\Http\Controllers;
use App\Http\Controllers\Controller;
use Exception;
use App\WebSockets\Socket;
use GuzzleHttp\Psr7\Response;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Ratchet\ConnectionInterface;
use function GuzzleHttp\Psr7\str;
use Psr\Http\Message\RequestInterface;
class CreateTunnelController extends Controller
{
protected $keepConnectionOpen = true;
public function handle(Request $request, ConnectionInterface $httpConnection)
{
app('expose.client')
->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();
});
}
}

View File

@@ -93,7 +93,7 @@
<p class="font-medium text-white flex justify-center">
<span class="inline-block">Waiting for requests on:
{% for subdomain in subdomains %}
<a class="underline" target="_blank" href="http://{{ subdomain }}">{{ subdomain }}</a>
<a class="underline" target="_blank" href="{{ subdomain }}">{{ subdomain }}</a>
{% endfor %}
</span>
</p>