Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Add support for overriding stats logger's base URL #115

Merged
merged 5 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions config/websockets.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@
*/
'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.
Expand Down
21 changes: 16 additions & 5 deletions src/Statistics/Logger/HttpStatisticsLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace BeyondCode\LaravelWebSockets\Statistics\Logger;

use Clue\React\Buzz\Browser;
use Ratchet\ConnectionInterface;
use function GuzzleHttp\Psr7\stream_for;
use BeyondCode\LaravelWebSockets\Apps\App;
use BeyondCode\LaravelWebSockets\Statistics\Http\Controllers\WebSocketStatisticsEntriesController;
use BeyondCode\LaravelWebSockets\Statistics\Statistic;
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
use BeyondCode\LaravelWebSockets\Statistics\Http\Controllers\WebSocketStatisticsEntriesController;
use Clue\React\Buzz\Browser;
use function GuzzleHttp\Psr7\stream_for;
use Ratchet\ConnectionInterface;

class HttpStatisticsLogger implements StatisticsLogger
{
Expand Down Expand Up @@ -79,7 +79,7 @@ public function save()
$this
->browser
->post(
action([WebSocketStatisticsEntriesController::class, 'store']),
$this->storeStatisticsUrl(),
['Content-Type' => 'application/json'],
stream_for(json_encode($postData))
);
Expand All @@ -88,4 +88,15 @@ public function save()
$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);
}
}