Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
allantatter committed May 6, 2021
0 parents commit 510a24b
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Optimist Digital <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Laravel Healthz

[![Latest Version on Packagist](https://img.shields.io/packagist/v/optimistdigital/laravel-healthz.svg?style=flat-square)](https://packagist.org/packages/optimistdigital/laravel-healthz)
[![Total Downloads](https://img.shields.io/packagist/dt/optimistdigital/laravel-healthz.svg?style=flat-square)](https://packagist.org/packages/optimistdigital/laravel-healthz)

Healthz is a Composer package that adds a health check route to the [Laravel](https://laravel.com) application.

Creates a route with path `/healthz` that response with 200 status code.

## Usage

In `routes/web.php` add a line:

```
Healthz::endpoint();
```

## Installation

Install the package in a Laravel project via Composer:

```
composer require optimistdigital/laravel-healthz
```

## Credits

- [Allan Tatter](https://github.com/allantatter)

## License

Laravel Healthz is open-sourced software licensed under the [MIT license](LICENSE.md).
34 changes: 34 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "optimistdigital/laravel-healthz",
"description": "Health check route for Laravel application.",
"keywords": [
"laravel",
"healthcheck",
"healthz",
"optimistdigital"
],
"license": "MIT",
"require": {
"laravel/framework": "^6.0 || ^7.0 || ^8.0"
},
"autoload": {
"psr-4": {
"OptimistDigital\\LaravelHealthz\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"OptimistDigital\\LaravelHealthz\\ServiceProvider"
],
"aliases": {
"Healthz": "OptimistDigital\\LaravelHealthz\\Facade"
}
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
22 changes: 22 additions & 0 deletions src/Facade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace OptimistDigital\LaravelHealthz;

class Facade extends \Illuminate\Support\Facades\Facade
{
protected static function getFacadeAccessor()
{
return 'healthz';
}

/**
* Register the healthz endpoint
*
* @param array $options
* @return void
*/
public static function endpoint(array $options = [])
{
static::$app->make('router')->healthz($options);
}
}
13 changes: 13 additions & 0 deletions src/HealthzController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace OptimistDigital\LaravelHealthz;

use Illuminate\Routing\Controller as BaseController;

class HealthzController extends BaseController
{
public function healthz()
{
return response('/healthz');
}
}
13 changes: 13 additions & 0 deletions src/HealthzRouteMethods.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace OptimistDigital\LaravelHealthz;

class HealthzRouteMethods
{
public function healthz()
{
return function ($options = []) {
$this->get('healthz', 'OptimistDigital\LaravelHealthz\HealthzController@healthz')->name('healthz');
};
}
}
27 changes: 27 additions & 0 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace OptimistDigital\LaravelHealthz;

use Illuminate\Support\Facades\Route;

class ServiceProvider extends \Illuminate\Support\ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
}

/**
* Perform post-registration booting of services.
*
* @return void
*/
public function boot()
{
Route::mixin(new HealthzRouteMethods);
}
}

0 comments on commit 510a24b

Please sign in to comment.