Major rewrite

This commit is contained in:
programmingPug
2025-01-14 14:47:10 -05:00
parent 0d7f77b1e3
commit 0f190a3f26
60 changed files with 966 additions and 4872 deletions

View File

@@ -0,0 +1,70 @@
using Microsoft.EntityFrameworkCore;
using SoilMoistureAPI.Data;
//using SoilMoistureAPI.Middleware;
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.ConfigureKestrel(options =>
{
options.ListenAnyIP(80); // Listen on port 80 for HTTP
// Optionally, listen on port 443 for HTTPS
/*
options.ListenAnyIP(443, listenOptions =>
{
listenOptions.UseHttps();
});
*/
});
// Add services to the container.
builder.Services.AddControllers();
// Configure CORS
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowClient",
builder =>
{
//builder.WithOrigins("http://localhost:3000", "http://soilmoisture_client:80")
builder.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod();
});
});
// Register the DB context with SQLite
builder.Services.AddDbContext<SoilMoistureContext>(options =>
options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection")));
// Add Swagger/OpenAPI support
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Apply migrations at startup
using (var scope = app.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<SoilMoistureContext>();
db.Database.Migrate();
}
// Use API Key Middleware
//app.UseMiddleware<ApiKeyMiddleware>();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseCors("AllowClient");
app.UseAuthorization();
app.MapControllers();
app.Run();