diff --git a/app/Client/Factory.php b/app/Client/Factory.php index 8908c3b..0b01e76 100644 --- a/app/Client/Factory.php +++ b/app/Client/Factory.php @@ -140,7 +140,7 @@ class Factory $this->router->post('/api/logs/{request_id}/data', AttachDataToLogController::class); $this->router->get('/api/logs/clear', ClearLogsController::class); - $this->app->route('/socket', new WsServer(new Socket()), ['*']); + $this->app->route('/socket', new WsServer(new Socket()), ['*'], ""); foreach ($this->router->getRoutes()->all() as $name => $route) { $this->app->routes->add($name, $route); @@ -162,7 +162,7 @@ class Factory config()->set('expose.dashboard_port', $dashboardPort); - $this->app = new App('127.0.0.1', $dashboardPort, '0.0.0.0', $this->loop); + $this->app = new App('0.0.0.0', $dashboardPort, '0.0.0.0', $this->loop); $this->addRoutes(); diff --git a/app/Client/Http/Controllers/ReplayLogController.php b/app/Client/Http/Controllers/ReplayLogController.php index e1b6ab6..583fb8b 100644 --- a/app/Client/Http/Controllers/ReplayLogController.php +++ b/app/Client/Http/Controllers/ReplayLogController.php @@ -4,8 +4,12 @@ namespace App\Client\Http\Controllers; use App\Client\Http\HttpClient; use App\Http\Controllers\Controller; +use App\Logger\LoggedRequest; use App\Logger\RequestLogger; +use GuzzleHttp\Psr7\Message; use GuzzleHttp\Psr7\Response; +use Illuminate\Support\Str; +use Laminas\Http\Header\GenericHeader; use function GuzzleHttp\Psr7\str; use Illuminate\Http\Request; use Ratchet\ConnectionInterface; @@ -29,13 +33,15 @@ class ReplayLogController extends Controller $loggedRequest = $this->requestLogger->findLoggedRequest($request->get('log')); if (is_null($loggedRequest)) { - $httpConnection->send(str(new Response(404))); + $httpConnection->send(Message::toString(new Response(404))); return; } - $this->httpClient->performRequest($loggedRequest->getRequestData()); + $loggedRequest->refreshId(); - $httpConnection->send(str(new Response(200))); + $this->httpClient->performRequest($loggedRequest->getRequest()->toString()); + + $httpConnection->send(Message::toString(new Response(200))); } } diff --git a/app/Commands/ShareCommand.php b/app/Commands/ShareCommand.php index fbe6092..6275cfd 100644 --- a/app/Commands/ShareCommand.php +++ b/app/Commands/ShareCommand.php @@ -10,7 +10,7 @@ use Symfony\Component\Console\Output\ConsoleOutput; class ShareCommand extends Command { - protected $signature = 'share {host} {--subdomain=} {--auth=} {--server-host=} {--server-port=}'; + protected $signature = 'share {host} {--subdomain=} {--auth=} {--server-host=} {--server-port=} {--dns=}'; protected $description = 'Share a local url with a remote expose server'; @@ -31,6 +31,14 @@ class ShareCommand extends Command $serverPort = $this->option('server-port') ?? config('expose.port', 8080); $auth = $this->option('auth') ?? config('expose.auth_token', ''); + if (strstr($this->argument('host'), 'host.docker.internal')) { + config(['expose.dns' => true]); + } + + if ($this->option('dns') !== null) { + config(['expose.dns' => empty($this->option('dns')) ? true : $this->option('dns')]); + } + (new Factory()) ->setLoop(app(LoopInterface::class)) ->setHost($serverHost) diff --git a/app/Logger/LoggedRequest.php b/app/Logger/LoggedRequest.php index d1626e7..7cdf073 100644 --- a/app/Logger/LoggedRequest.php +++ b/app/Logger/LoggedRequest.php @@ -3,6 +3,7 @@ namespace App\Logger; use Carbon\Carbon; +use Laminas\Http\Header\GenericHeader; use function GuzzleHttp\Psr7\parse_request; use Illuminate\Support\Arr; use Illuminate\Support\Str; @@ -211,4 +212,17 @@ class LoggedRequest implements \JsonSerializable return ''; } } + + public function refreshId() + { + $requestId = (string) Str::uuid(); + + $this->getRequest()->getHeaders()->removeHeader( + $this->getRequest()->getHeader('x-expose-request-id') + ); + + $this->getRequest()->getHeaders()->addHeader(new GenericHeader('x-expose-request-id', $requestId)); + + $this->id = $requestId; + } } diff --git a/config/expose.php b/config/expose.php index 8ed7dab..2defa53 100644 --- a/config/expose.php +++ b/config/expose.php @@ -29,6 +29,18 @@ return [ */ 'port' => 443, + /* + |-------------------------------------------------------------------------- + | DNS + |-------------------------------------------------------------------------- + | + | The DNS server to use when resolving the shared URLs. + | When Expose is running from within Docker containers, you should set this to + | `true` to fall-back to the system default DNS servers. + | + */ + 'dns' => '127.0.0.1', + /* |-------------------------------------------------------------------------- | Auth Token diff --git a/resources/views/client/dashboard.twig b/resources/views/client/dashboard.twig index cf8c497..e14d35c 100644 --- a/resources/views/client/dashboard.twig +++ b/resources/views/client/dashboard.twig @@ -2,7 +2,19 @@
- Waiting for requests on: - {% for subdomain in subdomains %} - {{ subdomain }} - {% endfor %} - -
-Expose
+ + Waiting for requests on: + {% for subdomain in subdomains %} + {{ subdomain }} + {% endfor %} + +| + | URL | -+ | Response | -+ | Duration |
|---|---|---|---|---|---|
|
- - @{ log.request.method } - @{ log.request.uri } + |
+ + @{ log.request.method } + @{ log.request.uri } - @{ log.subdomain } - @{ log.performed_at } + {% if subdomains|length > 1 %} + @{ log.subdomain } + {% endif %} + @{ log.performed_at } |
- + |
|
- + |
@{ log.duration }ms
@@ -186,15 +203,17 @@
-
-
-
- @{ currentLog.request.method } @{ currentLog.request.uri }
+
+ + @{ currentLog.request.method } @{ currentLog.request.uri } @@ -202,42 +221,41 @@-- - Received at: @{ currentLog.performed_at } -
-
- @{ currentLog.response.status } - @{ currentLog.response.reason }
-
+
+
+
+ @{ currentLog.response.status } - @{ currentLog.response.reason }
+
- @{ currentLog.response.status } - @{ currentLog.response.reason }
-
+ @{ currentLog.response.status } - @{ currentLog.response.reason }
+
- @{ currentLog.response.status } - @{ currentLog.response.reason }
-
+ @{ currentLog.response.status } - @{ currentLog.response.reason }
+
-
+ Received at: @{ currentLog.performed_at }
+
-
+
-
-
+ Query ParametersPost Parameters@@ -305,31 +323,31 @@
-
+ Headers
+ Request Body |
@{ currentLog.response.body }