feat(backend): Replace Node.js API with .NET 8
This commit completes the migration of the backend service from a Node.js/Express application to an ASP.NET Core 8 Minimal API. - Re-implemented all API endpoints in C# for improved performance and type safety. - Updated the Gitea Actions workflow to use the `setup-dotnet` action, `dotnet publish` for building, and now caches NuGet packages. - Modified the deployment to create an `appsettings.Production.json` file from Gitea secrets instead of a `.env` file. - Updated the PM2 ecosystem configuration to run the application using the `dotnet` interpreter.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
|
||||
using JoaoLoureiro.Portfolio.Infrastructure.Settings;
|
||||
using MailKit.Net.Smtp;
|
||||
using MailKit.Security;
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace JoaoLoureiro.Portfolio.Infrastructure.HealthCheck;
|
||||
|
||||
public class SmtpHealthCheck(IOptions<SmtpSettings> smtpSettings) : IHealthCheck
|
||||
{
|
||||
private readonly SmtpSettings _smtpSettings = smtpSettings.Value;
|
||||
|
||||
public async Task<HealthCheckResult> CheckHealthAsync(
|
||||
HealthCheckContext context,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
using var client = new SmtpClient();
|
||||
try
|
||||
{
|
||||
await client.ConnectAsync(_smtpSettings.Host, _smtpSettings.Port, SecureSocketOptions.StartTlsWhenAvailable, cancellationToken);
|
||||
await client.AuthenticateAsync(_smtpSettings.User, _smtpSettings.Pass, cancellationToken);
|
||||
await client.DisconnectAsync(true, cancellationToken);
|
||||
return HealthCheckResult.Healthy("SMTP server is responding correctly.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return HealthCheckResult.Unhealthy("Failed to connect or authenticate with SMTP server.", exception: ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user