buildout full stack functionality
This commit is contained in:
29
backend/Controllers/InfoController.cs
Normal file
29
backend/Controllers/InfoController.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Backend.Controllers;
|
||||
|
||||
[Route("v1/[controller]")]
|
||||
[ApiController]
|
||||
public class InfoController : ControllerBase
|
||||
{
|
||||
private readonly IWebHostEnvironment _environment;
|
||||
|
||||
public InfoController(IWebHostEnvironment environment)
|
||||
{
|
||||
_environment = environment;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Get()
|
||||
{
|
||||
var assembly = typeof(InfoController).Assembly.GetName();
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
name = assembly.Name ?? "backend",
|
||||
version = assembly.Version?.ToString(3) ?? "0.0.0",
|
||||
environment = _environment.EnvironmentName,
|
||||
timestamp = DateTime.UtcNow,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,17 @@
|
||||
using System.Text.Json;
|
||||
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
// using Backend.Data
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
builder.Services.AddHealthChecks();
|
||||
|
||||
builder.Services.AddCors();
|
||||
|
||||
@@ -32,6 +36,19 @@ app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapHealthChecks("/health", new HealthCheckOptions
|
||||
{
|
||||
ResponseWriter = async (context, report) =>
|
||||
{
|
||||
context.Response.ContentType = "application/json";
|
||||
var payload = JsonSerializer.Serialize(new
|
||||
{
|
||||
status = report.Status == HealthStatus.Healthy ? "healthy" : "unhealthy",
|
||||
});
|
||||
await context.Response.WriteAsync(payload);
|
||||
},
|
||||
});
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
@@ -1,6 +1,11 @@
|
||||
@Backend_HostAddress = http://localhost:3000
|
||||
@Backend_HostAddress = http://localhost:5231
|
||||
|
||||
GET {{Backend_HostAddress}}/weatherforecast/
|
||||
GET {{Backend_HostAddress}}/health
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
###
|
||||
|
||||
GET {{Backend_HostAddress}}/v1/info
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
|
||||
Reference in New Issue
Block a user