mirror of
https://github.com/bitinflow/expose.git
synced 2026-03-15 14:35:55 +00:00
wip
This commit is contained in:
@@ -41,9 +41,9 @@ class Client
|
|||||||
{
|
{
|
||||||
$token = config('expose.auth_token');
|
$token = config('expose.auth_token');
|
||||||
|
|
||||||
$protocol = $this->configuration->port() === 443 ? "wss" : "ws";
|
$wsProtocol = $this->configuration->port() === 443 ? "wss" : "ws";
|
||||||
|
|
||||||
connect($protocol."://{$this->configuration->host()}:{$this->configuration->port()}/expose/control?authToken={$token}", [], [
|
connect($wsProtocol."://{$this->configuration->host()}:{$this->configuration->port()}/expose/control?authToken={$token}", [], [
|
||||||
'X-Expose-Control' => 'enabled',
|
'X-Expose-Control' => 'enabled',
|
||||||
], $this->loop)
|
], $this->loop)
|
||||||
->then(function (WebSocket $clientConnection) use ($sharedUrl, $subdomain) {
|
->then(function (WebSocket $clientConnection) use ($sharedUrl, $subdomain) {
|
||||||
@@ -67,7 +67,14 @@ class Client
|
|||||||
});
|
});
|
||||||
|
|
||||||
$connection->on('authenticated', function ($data) {
|
$connection->on('authenticated', function ($data) {
|
||||||
$this->logger->info("Connected to http://$data->subdomain.{$this->configuration->host()}:{$this->configuration->port()}");
|
$httpProtocol = $this->configuration->port() === 443 ? "https" : "http";
|
||||||
|
$host = $this->configuration->host();
|
||||||
|
|
||||||
|
if ($httpProtocol !== 'https') {
|
||||||
|
$host .= ":{$this->configuration->port()}";
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->logger->info("Connected to {$httpProtocol}://{$data->subdomain}.{$host}");
|
||||||
|
|
||||||
static::$subdomains[] = "$data->subdomain.{$this->configuration->host()}:{$this->configuration->port()}";
|
static::$subdomains[] = "$data->subdomain.{$this->configuration->host()}:{$this->configuration->port()}";
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -82,10 +82,8 @@ class Factory
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function addExposeRoutes()
|
protected function addTunnelRoute()
|
||||||
{
|
{
|
||||||
$this->router->get('/expose/control', ControlMessageController::class, 'request.headers.get("x-expose-control") matches "/enabled/i"');
|
|
||||||
|
|
||||||
$this->router->addSymfonyRoute('tunnel',
|
$this->router->addSymfonyRoute('tunnel',
|
||||||
new Route('/{__catchall__}', [
|
new Route('/{__catchall__}', [
|
||||||
'_controller' => app(TunnelMessageController::class),
|
'_controller' => app(TunnelMessageController::class),
|
||||||
@@ -94,6 +92,18 @@ class Factory
|
|||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function addControlConnectionRoute(): WsServer
|
||||||
|
{
|
||||||
|
$wsServer = new WsServer(app(ControlMessageController::class));
|
||||||
|
|
||||||
|
$this->router->addSymfonyRoute('expose-control',
|
||||||
|
new Route('/expose/control', [
|
||||||
|
'_controller' => $wsServer,
|
||||||
|
], [], [], '', [], [], 'request.headers.get("x-expose-control") matches "/enabled/i"'));
|
||||||
|
|
||||||
|
return $wsServer;
|
||||||
|
}
|
||||||
|
|
||||||
protected function addAdminRoutes()
|
protected function addAdminRoutes()
|
||||||
{
|
{
|
||||||
$adminCondition = 'request.headers.get("Host") matches "/'.config('expose.dashboard_subdomain').'./i"';
|
$adminCondition = 'request.headers.get("Host") matches "/'.config('expose.dashboard_subdomain').'./i"';
|
||||||
@@ -143,7 +153,9 @@ class Factory
|
|||||||
|
|
||||||
$this->addAdminRoutes();
|
$this->addAdminRoutes();
|
||||||
|
|
||||||
$this->addExposeRoutes();
|
$this->addTunnelRoute();
|
||||||
|
|
||||||
|
$controlConnection = $this->addControlConnectionRoute();
|
||||||
|
|
||||||
$urlMatcher = new UrlMatcher($this->router->getRoutes(), new RequestContext);
|
$urlMatcher = new UrlMatcher($this->router->getRoutes(), new RequestContext);
|
||||||
|
|
||||||
@@ -151,7 +163,11 @@ class Factory
|
|||||||
|
|
||||||
$http = new HttpServer($router);
|
$http = new HttpServer($router);
|
||||||
|
|
||||||
return new IoServer($http, $socket, $this->loop);
|
$server = new IoServer($http, $socket, $this->loop);
|
||||||
|
|
||||||
|
$controlConnection->enableKeepAlive($this->loop);
|
||||||
|
|
||||||
|
return $server;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function bindDatabase()
|
protected function bindDatabase()
|
||||||
|
|||||||
@@ -60,19 +60,6 @@ class RouteGenerator
|
|||||||
|
|
||||||
protected function getRoute(string $method, string $uri, $action, string $condition = ''): Route
|
protected function getRoute(string $method, string $uri, $action, string $condition = ''): Route
|
||||||
{
|
{
|
||||||
$action = is_subclass_of($action, MessageComponentInterface::class)
|
return new Route($uri, ['_controller' => app($action)], [], [], null, [], [$method], $condition);
|
||||||
? $this->createWebSocketsServer($action)
|
|
||||||
: app($action);
|
|
||||||
|
|
||||||
return new Route($uri, ['_controller' => $action], [], [], null, [], [$method], $condition);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function createWebSocketsServer(string $action): WsServer
|
|
||||||
{
|
|
||||||
$wServer = new WsServer(app($action));
|
|
||||||
|
|
||||||
$wServer->enableKeepAlive(app(LoopInterface::class));
|
|
||||||
|
|
||||||
return $wServer;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user