Files
mindforge/Mindforge.API/Program.cs
Jose Henrique b9736293d3
All checks were successful
Mindforge API Build and Deploy / Build Mindforge API Image (push) Successful in 3m39s
Mindforge Cronjob Build and Deploy / Build Mindforge Cronjob Image (push) Successful in 3m49s
Mindforge API Build and Deploy / Deploy Mindforge API (internal) (push) Successful in 38s
Mindforge Cronjob Build and Deploy / Deploy Mindforge Cronjob (internal) (push) Successful in 30s
moving to openrouter
2026-04-04 21:09:18 -03:00

84 lines
2.5 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>();
// 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 openAiApiUrl = builder.Configuration["OPENAI_API_URL"];
var openAiToken = builder.Configuration["OPENAI_TOKEN"];
var openAiModel = builder.Configuration["OPENAI_MODEL"];
if (string.IsNullOrEmpty(openAiApiUrl))
app.Logger.LogWarning("OPENAI_API_URL not found in configuration.");
if (string.IsNullOrEmpty(openAiToken))
app.Logger.LogWarning("OPENAI_TOKEN not found in configuration.");
if (string.IsNullOrEmpty(openAiModel))
app.Logger.LogWarning("OPENAI_MODEL 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();