Skip to content

Commit 57d5624

Browse files
committed
add healthcheck
1 parent ef11884 commit 57d5624

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace rabbit\httpserver\middleware;
5+
6+
use Psr\Http\Message\ResponseInterface;
7+
use Psr\Http\Message\ServerRequestInterface;
8+
use Psr\Http\Server\MiddlewareInterface;
9+
use Psr\Http\Server\RequestHandlerInterface;
10+
use rabbit\core\Context;
11+
12+
/**
13+
* Class HealthCheckMiddleware
14+
* @package rabbit\httpserver\middleware
15+
*/
16+
class HealthCheckMiddleware implements MiddlewareInterface
17+
{
18+
/** @var string */
19+
protected $health;
20+
21+
/**
22+
* ReqHandlerMiddleware constructor.
23+
* @param string|null $health
24+
*/
25+
public function __construct(string $health = '/health')
26+
{
27+
$this->health = $health;
28+
}
29+
30+
/**
31+
* @param ServerRequestInterface $request
32+
* @param RequestHandlerInterface $handler
33+
* @return ResponseInterface
34+
*/
35+
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
36+
{
37+
$url = $request->getUri()->getPath();
38+
if ($url === $this->health) {
39+
return Context::get('response');
40+
}
41+
return $handler->handle($request);
42+
}
43+
}

0 commit comments

Comments
 (0)