diff --git a/config/websockets.php b/config/websockets.php index 6a2e7f0..a0d1516 100644 --- a/config/websockets.php +++ b/config/websockets.php @@ -92,6 +92,14 @@ return [ */ 'delete_statistics_older_than_days' => 60, + /* + * By default, the websockets server attempts to connect to whatever + * your APP_URL is set to. If running in a more complex environment, + * you may wish to override the base URL for internal requests to + * allow statistics to be collected. + */ + 'base_url_override' => null, + /* * Use an DNS resolver to make the requests to the statistics logger * default is to resolve everything to 127.0.0.1. diff --git a/src/Statistics/Logger/HttpStatisticsLogger.php b/src/Statistics/Logger/HttpStatisticsLogger.php index 1cc0201..d732025 100644 --- a/src/Statistics/Logger/HttpStatisticsLogger.php +++ b/src/Statistics/Logger/HttpStatisticsLogger.php @@ -79,7 +79,7 @@ class HttpStatisticsLogger implements StatisticsLogger $this ->browser ->post( - action([WebSocketStatisticsEntriesController::class, 'store']), + $this->storeStatisticsUrl(), ['Content-Type' => 'application/json'], stream_for(json_encode($postData)) ); @@ -88,4 +88,15 @@ class HttpStatisticsLogger implements StatisticsLogger $statistic->reset($currentConnectionCount); } } + + protected function storeStatisticsUrl(): string + { + $action = [WebSocketStatisticsEntriesController::class, 'store']; + + $overridenUrl = config('websockets.statistics.base_url_override'); + + return $overridentUrl + ? $overridenUrl.action($action, [], false) + : action($action); + } }