70 lines
1.9 KiB
C#
70 lines
1.9 KiB
C#
using FichaBackend;
|
|
using FichaBackend.Services;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.OpenApi.Models;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
string GetEnv(string envName, string settingsName = "")
|
|
{
|
|
string? dbConString = builder.Configuration.GetConnectionString(settingsName) ?? Environment.GetEnvironmentVariable(envName);
|
|
if (!string.IsNullOrEmpty(dbConString))
|
|
return dbConString;
|
|
|
|
Console.WriteLine($"Environment variable {envName} not found.");
|
|
return String.Empty;
|
|
}
|
|
|
|
builder.Services.AddControllers();
|
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
builder.Services.AddSwaggerGen(c =>
|
|
{
|
|
c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "ApiDocumentation.xml"));
|
|
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Ficha Backend", Version = "v1" });
|
|
});
|
|
|
|
// Add services to the container.
|
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
// builder.Services.AddEndpointsApiExplorer();
|
|
// builder.Services.AddSwaggerGen();
|
|
|
|
// Database
|
|
string? dbConString = GetEnv("CONNECTION_STRING", "DefaultConnection");
|
|
|
|
builder.Services.AddDbContext<DatabaseContext>(options =>
|
|
{ options.UseNpgsql(dbConString); });
|
|
|
|
// HealthChecks
|
|
builder.Services.AddHealthChecks()
|
|
.AddNpgSql(dbConString);
|
|
|
|
// Services
|
|
builder.Services.AddScoped<IPublicDataService, PublicDataService>();
|
|
|
|
// cors
|
|
builder.Services.AddCors(options =>
|
|
{
|
|
options.AddDefaultPolicy(
|
|
policy =>
|
|
{
|
|
policy.WithOrigins("*")
|
|
.AllowAnyHeader()
|
|
.AllowAnyMethod();
|
|
});
|
|
});
|
|
|
|
var app = builder.Build();
|
|
|
|
// Configure the HTTP request pipeline.
|
|
// if (app.Environment.IsDevelopment())
|
|
// {
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI();
|
|
// }
|
|
|
|
app.MapHealthChecks("/health");
|
|
|
|
app.MapControllers();
|
|
|
|
app.Run(); |