mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2026-02-17 20:24:28 +01:00
Merge pull request #1471 from dennisreimann/api-health-endpoint
GreenField: Add health check endpoint
This commit is contained in:
16
BTCPayServer.Client/BTCPayServerClient.Health.cs
Normal file
16
BTCPayServer.Client/BTCPayServerClient.Health.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BTCPayServer.Client.Models;
|
||||
|
||||
namespace BTCPayServer.Client
|
||||
{
|
||||
public partial class BTCPayServerClient
|
||||
{
|
||||
public virtual async Task<ApiHealthData> GetHealth(CancellationToken token = default)
|
||||
{
|
||||
var response = await _httpClient.SendAsync(CreateHttpRequest("api/v1/health"), token);
|
||||
return await HandleResponse<ApiHealthData>(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
10
BTCPayServer.Client/Models/ApiHealthData.cs
Normal file
10
BTCPayServer.Client/Models/ApiHealthData.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using BTCPayServer.Client.JsonConverters;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace BTCPayServer.Client.Models
|
||||
{
|
||||
public class ApiHealthData
|
||||
{
|
||||
public bool Synchronized { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -272,5 +272,20 @@ namespace BTCPayServer.Tests
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Fact(Timeout = TestTimeout)]
|
||||
[Trait("Integration", "Integration")]
|
||||
public async Task HealthControllerTests()
|
||||
{
|
||||
using (var tester = ServerTester.Create())
|
||||
{
|
||||
await tester.StartAsync();
|
||||
var unauthClient = new BTCPayServerClient(tester.PayTester.ServerUri);
|
||||
|
||||
var apiHealthData = await unauthClient.GetHealth();
|
||||
Assert.NotNull(apiHealthData);
|
||||
Assert.True(apiHealthData.Synchronized);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
22
BTCPayServer/Controllers/GreenField/HealthController.cs
Normal file
22
BTCPayServer/Controllers/GreenField/HealthController.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using BTCPayServer.HostedServices;
|
||||
using BTCPayServer.Client.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace BTCPayServer.Controllers.GreenField
|
||||
{
|
||||
[Controller]
|
||||
public class HealthController : ControllerBase
|
||||
{
|
||||
[AllowAnonymous]
|
||||
[HttpGet("~/api/v1/health")]
|
||||
public ActionResult GetHealth(NBXplorerDashboard dashBoard)
|
||||
{
|
||||
ApiHealthData model = new ApiHealthData()
|
||||
{
|
||||
Synchronized = dashBoard.IsFullySynched()
|
||||
};
|
||||
return Ok(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
46
BTCPayServer/wwwroot/swagger/v1/swagger.template.health.json
Normal file
46
BTCPayServer/wwwroot/swagger/v1/swagger.template.health.json
Normal file
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"paths": {
|
||||
"/api/v1/health": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"Health"
|
||||
],
|
||||
"summary": "Get health status",
|
||||
"description": "Check the instance health status",
|
||||
"operationId": "Health_GetHealth",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Instance is up",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/ApplicationHealthData"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"security": []
|
||||
}
|
||||
}
|
||||
},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"ApplicationHealthData": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"synchronized": {
|
||||
"type": "boolean",
|
||||
"description": "True if the instance is fully synchronized, according to NBXplorer"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"tags": [
|
||||
{
|
||||
"name": "Health"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user