books/backend/Books.Api/Program.cs

46 lines
1.1 KiB
C#
Raw Normal View History

using Books.Api;
using Books.Api.GraphQL;
using GraphQL;
using GraphQL.Server.Ui.Altair;
using Hangfire;
// Enable legacy timestamp behavior for Npgsql 6.0+
// This allows DateTimeOffset with non-UTC offsets to be written to timestamptz columns
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
var builder = WebApplication.CreateBuilder(args);
// Configure EventFlow, Hangfire, GraphQL and all services
Startup.ConfigureServices(builder.Services, builder.Configuration, builder.Environment);
var app = builder.Build();
// Configure the HTTP request pipeline
if (app.Environment.IsDevelopment())
{
app.UseHangfireDashboard();
}
app.UseHttpsRedirection();
// CORS must come before auth
app.UseCors();
// Authentication & Authorization
app.UseAuthentication();
app.UseAuthorization();
// Map controllers (for AuthController)
app.MapControllers();
// GraphQL endpoint
app.UseGraphQL<BooksSchema>("/graphql");
// GraphQL UI (development only) - use external tools like Altair, Insomnia, or GraphiQL
if (app.Environment.IsDevelopment())
{
app.UseGraphQLAltair("/graphql/ui");
}
app.Run();