89 lines
2.4 KiB
C#
89 lines
2.4 KiB
C#
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Mindforge.API.Providers;
|
|
using Mindforge.API.Services;
|
|
using Mindforge.API.Services.Interfaces;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// Ensure environment variables are loaded into IConfiguration
|
|
builder.Configuration.AddEnvironmentVariables();
|
|
|
|
// Add services to the container.
|
|
builder.Services.AddControllers();
|
|
builder.Logging.AddConsole();
|
|
builder.Logging.AddDebug();
|
|
|
|
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
|
builder.Services.AddOpenApi();
|
|
|
|
// Configure CORS
|
|
builder.Services.AddCors(options =>
|
|
{
|
|
options.AddPolicy("AllowAll", policy =>
|
|
{
|
|
policy.AllowAnyOrigin()
|
|
.AllowAnyMethod()
|
|
.AllowAnyHeader();
|
|
});
|
|
});
|
|
|
|
// Register HttpClient for providers
|
|
builder.Services.AddHttpClient();
|
|
|
|
// Register Providers
|
|
builder.Services.AddScoped<ILlmApiProvider, OpenAIApiProvider>();
|
|
builder.Services.AddScoped<ILlmApiProvider, GeminiApiProvider>();
|
|
|
|
// Register Services
|
|
builder.Services.AddScoped<IAgentService, AgentService>();
|
|
builder.Services.AddScoped<IFileService, FileService>();
|
|
builder.Services.AddScoped<IFlashcardService, FlashcardService>();
|
|
builder.Services.AddScoped<IGiteaService, GiteaService>();
|
|
|
|
var app = builder.Build();
|
|
|
|
app.UseCors("AllowAll");
|
|
|
|
app.UseMiddleware<Mindforge.API.Middlewares.ExceptionHandlingMiddleware>();
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.MapOpenApi();
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
app.UseAuthorization();
|
|
app.MapControllers();
|
|
|
|
// Check for env vars
|
|
var openAiKey = builder.Configuration["OPENAI_API_KEY"];
|
|
var geminiKey = builder.Configuration["GEMINI_API_KEY"];
|
|
|
|
if (string.IsNullOrEmpty(openAiKey))
|
|
{
|
|
app.Logger.LogWarning("OPENAI_API_KEY not found in configuration.");
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(geminiKey))
|
|
{
|
|
app.Logger.LogWarning("GEMINI_API_KEY not found in configuration.");
|
|
}
|
|
|
|
var giteaRepoUrl = builder.Configuration["GITEA_REPO_URL"];
|
|
var giteaAccessToken = builder.Configuration["GITEA_ACCESS_TOKEN"];
|
|
|
|
if (string.IsNullOrEmpty(giteaRepoUrl))
|
|
{
|
|
app.Logger.LogWarning("GITEA_REPO_URL not found in configuration. Repository features will not work.");
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(giteaAccessToken))
|
|
{
|
|
app.Logger.LogWarning("GITEA_ACCESS_TOKEN not found in configuration. Repository features will not work.");
|
|
}
|
|
|
|
app.Run();
|