Skip to content

Commit

Permalink
Merge pull request #2 from chocofamilyme/bug.fix
Browse files Browse the repository at this point in the history
Fix route /health/extended
  • Loading branch information
Vadim89 authored Dec 25, 2020
2 parents 71c2ec1 + d83a225 commit c9b5113
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 29 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 2.0.1
- Fix route /health/extended. Update your config healthcheck.php

## 2.0.0
- Laravel 8 support
- Minimum PHP version is set to 7.4
Expand Down
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ For example you want to check "Database Connection" of your microservice.

# Installation
```bash
composer require chocofamilyme/laravel-healthcheck ^0.0
composer require chocofamilyme/laravel-healthcheck ^2.0
```

# Publishing the configuration (optional)
Expand All @@ -28,7 +28,7 @@ php artisan vendor:publish --provider="Chocofamilyme\LaravelHealthCheck\Provider
"STORAGE": "OK"
}
```
- /health/extendet
- /health/extended
```json
{
"DB": {
Expand Down Expand Up @@ -67,7 +67,7 @@ return [

# Responses
There is a configuration param which describes which response class to use to output the response. For example
- /health - Chocofamilyme\LaravelHealthCheck\Responses\DefaultResponse::class
- /health - Chocofamilyme\LaravelHealthCheck\Responses\Response::class
output would look like this
```json
{
Expand All @@ -78,13 +78,10 @@ output would look like this
}
```

- /health - Chocofamilyme\LaravelHealthCheck\Responses\ChocofamilyResponse::class
- /health - Chocofamilyme\LaravelHealthCheck\Responses\Response::class
output would look like this
```json
{
"error_code": 0,
"status": "success",
"message": "Everything is fine",
"data": {
"DB": "OK",
"CACHE": "OK",
Expand All @@ -94,4 +91,4 @@ output would look like this
}
```

Feel free to add your responses, if you want for example to output it in a view instead json.
Feel free to add your responses, if you want for example to output it in a view instead json.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.5",
"vimeo/psalm": "^3.18"
"vimeo/psalm": "^4.3"
},
"autoload": {
"psr-4": {
Expand Down
13 changes: 7 additions & 6 deletions src/Controllers/HealthCheckController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Chocofamilyme\LaravelHealthCheck\Controllers;

use Illuminate\Contracts\Config\Repository;
use Illuminate\Http\JsonResponse;
use Illuminate\Routing\Controller;
use Chocofamilyme\LaravelHealthCheck\Services\ComponentCheckService;

Expand All @@ -23,9 +24,9 @@ public function __construct(Repository $config)
}

/**
* @return \Illuminate\Http\JsonResponse
* @return JsonResponse
*/
public function simple(): \Illuminate\Http\JsonResponse
public function simple(): JsonResponse
{
$checks = $this->componentCheck->getResponse();
$responseClass = $this->config->get('healthcheck.response');
Expand All @@ -34,17 +35,17 @@ public function simple(): \Illuminate\Http\JsonResponse
}

/**
* @return \Illuminate\Http\JsonResponse
* @return JsonResponse
*/
public function extendet(): ?\Illuminate\Http\JsonResponse
public function extended(): ?JsonResponse
{
if (!$this->config->get('healthcheck.extendet')) {
if (!$this->config->get('healthcheck.extended')) {
return null;
}

$checks = $this->componentCheck->getResponse();
$responseClass = $this->config->get('healthcheck.response');

return (new $responseClass())->extendetResponse($checks);
return (new $responseClass())->extendedResponse($checks);
}
}
5 changes: 3 additions & 2 deletions src/Providers/HealthCheckServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Chocofamilyme\LaravelHealthCheck\Providers;

use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Support\ServiceProvider;

class HealthCheckServiceProvider extends ServiceProvider
Expand All @@ -10,15 +11,15 @@ class HealthCheckServiceProvider extends ServiceProvider
* Register services.
*
* @return void
* @throws \Illuminate\Contracts\Container\BindingResolutionException
* @throws BindingResolutionException
*/
public function register()
{
// Route
$this->loadRoutesFrom(__DIR__ . '/../routes/web.php');

// Controller
$this->app->make('Chocofamilyme\LaravelHealthCheck\Controllers\HealthCheckController');
$this->app->make(\Chocofamilyme\LaravelHealthCheck\Controllers\HealthCheckController::class);

// Merge our config with application config
$this->mergeConfigFrom(
Expand Down
2 changes: 1 addition & 1 deletion src/Responses/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function simpleResponse(array $checks): SymfonyResponse
}

/**
* Return data in extendet way
* Return data in extended way
*
* @psalm-suppress UndefinedFunction
*
Expand Down
18 changes: 9 additions & 9 deletions src/config/healthcheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@

/*
|--------------------------------------------------------------------------
| Route for the extendet response
| Route for the extended response
|--------------------------------------------------------------------------
|
| Specify route for the extendet response
| Specify route for the extended response
|
*/

'routeextendet' => '/health/extendet',
'routeextended' => '/health/extended',

/*
|--------------------------------------------------------------------------
Expand All @@ -39,16 +39,16 @@

/*
|--------------------------------------------------------------------------
| Enable extendet health check endpoint
| Enable extended health check endpoint
|--------------------------------------------------------------------------
|
| Enable extendet endpoint for healthchecks with more information what
| Enable extended endpoint for healthchecks with more information what
| went wrong, this is dangerous because in the exception messages may be
| confidential information
|
*/

'extendet' => false,
'extended' => true,

/*
|--------------------------------------------------------------------------
Expand All @@ -64,9 +64,9 @@
*/

'componentChecks' => [
'DB' => Chocofamilyme\LaravelHealthCheck\Services\Checks\DatabaseComponentCheck::class,
'CACHE' => Chocofamilyme\LaravelHealthCheck\Services\Checks\CacheComponentCheck::class,
'SESSIONS' => Chocofamilyme\LaravelHealthCheck\Services\Checks\SessionsComponentCheck::class,
//'DB' => Chocofamilyme\LaravelHealthCheck\Services\Checks\DatabaseComponentCheck::class,
//'CACHE' => Chocofamilyme\LaravelHealthCheck\Services\Checks\CacheComponentCheck::class,
//'SESSIONS' => Chocofamilyme\LaravelHealthCheck\Services\Checks\SessionsComponentCheck::class,
//'STORAGE' => Chocofamilyme\LaravelHealthCheck\Services\Checks\StorageComponentCheck::class,
]
];
4 changes: 2 additions & 2 deletions src/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@

/** @psalm-suppress UndefinedFunction */
Route::get(
config('healthcheck.routeextendet', '/health/extendet'),
'Chocofamilyme\LaravelHealthCheck\Controllers\HealthCheckController@extendet'
config('healthcheck.routeextended', '/health/extended'),
'Chocofamilyme\LaravelHealthCheck\Controllers\HealthCheckController@extended'
);

0 comments on commit c9b5113

Please sign in to comment.