Added healthcheck controller
This commit is contained in:
parent
86fbf76a0e
commit
1ec637fb51
|
|
@ -267,6 +267,8 @@ return [
|
||||||
|
|
||||||
'websocket' => \BeyondCode\LaravelWebSockets\Server\WebSocketHandler::class,
|
'websocket' => \BeyondCode\LaravelWebSockets\Server\WebSocketHandler::class,
|
||||||
|
|
||||||
|
'health' => \BeyondCode\LaravelWebSockets\Server\HealthHandler::class,
|
||||||
|
|
||||||
'trigger_event' => \BeyondCode\LaravelWebSockets\API\TriggerEvent::class,
|
'trigger_event' => \BeyondCode\LaravelWebSockets\API\TriggerEvent::class,
|
||||||
|
|
||||||
'fetch_channels' => \BeyondCode\LaravelWebSockets\API\FetchChannels::class,
|
'fetch_channels' => \BeyondCode\LaravelWebSockets\API\FetchChannels::class,
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,65 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeyondCode\LaravelWebSockets\Server;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use GuzzleHttp\Psr7\Response;
|
||||||
|
use Psr\Http\Message\RequestInterface;
|
||||||
|
use Ratchet\ConnectionInterface;
|
||||||
|
use Ratchet\RFC6455\Messaging\MessageInterface;
|
||||||
|
use Ratchet\WebSocket\MessageComponentInterface;
|
||||||
|
|
||||||
|
class HealthHandler implements MessageComponentInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle the socket opening.
|
||||||
|
*
|
||||||
|
* @param \Ratchet\ConnectionInterface $connection
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function onOpen(ConnectionInterface $connection, RequestInterface $request = null)
|
||||||
|
{
|
||||||
|
$response = new Response(
|
||||||
|
200,
|
||||||
|
['Content-Type' => 'application/json'],
|
||||||
|
json_encode(['ok' => true])
|
||||||
|
);
|
||||||
|
|
||||||
|
tap($connection)->send(\GuzzleHttp\Psr7\str($response))->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the incoming message.
|
||||||
|
*
|
||||||
|
* @param \Ratchet\ConnectionInterface $connection
|
||||||
|
* @param \Ratchet\RFC6455\Messaging\MessageInterface $message
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function onMessage(ConnectionInterface $connection, MessageInterface $message)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the websocket close.
|
||||||
|
*
|
||||||
|
* @param \Ratchet\ConnectionInterface $connection
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function onClose(ConnectionInterface $connection)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the websocket errors.
|
||||||
|
*
|
||||||
|
* @param \Ratchet\ConnectionInterface $connection
|
||||||
|
* @param WebSocketException $exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function onError(ConnectionInterface $connection, Exception $exception)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -49,6 +49,7 @@ class Router
|
||||||
$this->get('/apps/{appId}/channels', config('websockets.handlers.fetch_channels'));
|
$this->get('/apps/{appId}/channels', config('websockets.handlers.fetch_channels'));
|
||||||
$this->get('/apps/{appId}/channels/{channelName}', config('websockets.handlers.fetch_channel'));
|
$this->get('/apps/{appId}/channels/{channelName}', config('websockets.handlers.fetch_channel'));
|
||||||
$this->get('/apps/{appId}/channels/{channelName}/users', config('websockets.handlers.fetch_users'));
|
$this->get('/apps/{appId}/channels/{channelName}/users', config('websockets.handlers.fetch_users'));
|
||||||
|
$this->get('/health', config('websockets.handlers.health'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeyondCode\LaravelWebSockets\Test;
|
||||||
|
|
||||||
|
use BeyondCode\LaravelWebSockets\Server\HealthHandler;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
class HealthTest extends TestCase
|
||||||
|
{
|
||||||
|
public function test_health_handler()
|
||||||
|
{
|
||||||
|
$connection = $this->newConnection();
|
||||||
|
|
||||||
|
$this->pusherServer = app(HealthHandler::class);
|
||||||
|
|
||||||
|
$this->pusherServer->onOpen($connection);
|
||||||
|
|
||||||
|
$this->assertTrue(
|
||||||
|
Str::contains($connection->sentRawData[0], '{"ok":true}')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue