Add project files.
This commit is contained in:
80
Gateway/Program.cs
Normal file
80
Gateway/Program.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using Gateway.Data;
|
||||
using Gateway.ProviderClients;
|
||||
using Gateway.Security;
|
||||
using Gateway.Services;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// --------------------
|
||||
// Container-friendly HTTP binding
|
||||
// --------------------
|
||||
var port = Environment.GetEnvironmentVariable("PORT") ?? "8080";
|
||||
builder.WebHost.UseUrls($"http://0.0.0.0:{port}");
|
||||
|
||||
// --------------------
|
||||
// Services
|
||||
// --------------------
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
// Data & business services
|
||||
builder.Services.AddScoped<SqlService>();
|
||||
builder.Services.AddScoped<ExecutionService>();
|
||||
|
||||
// Authentication context (scoped - one per request)
|
||||
builder.Services.AddScoped<ClientContext>();
|
||||
|
||||
// Provider clients
|
||||
builder.Services.AddHttpClient<GoogleProviderClient>(client =>
|
||||
{
|
||||
var baseUrl = builder.Configuration["Provider:Google:BaseUrl"]
|
||||
?? Environment.GetEnvironmentVariable("GOOGLE_PROVIDER_URL")
|
||||
?? "";
|
||||
if (!string.IsNullOrWhiteSpace(baseUrl))
|
||||
client.BaseAddress = new Uri(baseUrl.EndsWith("/") ? baseUrl : baseUrl + "/");
|
||||
});
|
||||
|
||||
// HTTP client factory for ExecutionService
|
||||
builder.Services.AddHttpClient();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// --------------------
|
||||
// Middleware pipeline
|
||||
// --------------------
|
||||
|
||||
// Swagger (enabled for all environments in containers)
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
|
||||
// Health check endpoint (before auth & logging)
|
||||
app.MapGet("/health", () => Results.Ok(new
|
||||
{
|
||||
ok = true,
|
||||
service = "Gateway",
|
||||
timestamp = DateTimeOffset.UtcNow
|
||||
}));
|
||||
|
||||
// Root endpoint
|
||||
app.MapGet("/", () => Results.Ok(new
|
||||
{
|
||||
service = "Gateway API",
|
||||
version = "1.0.0",
|
||||
status = "Application Gateway running"
|
||||
}));
|
||||
|
||||
// Access logging middleware (captures all requests)
|
||||
// Placed BEFORE auth so we log even failed auth attempts
|
||||
app.UseAccessLogging();
|
||||
|
||||
// Client authentication middleware (multi-provider)
|
||||
// - Validates JWTs from Microsoft, Google, etc.
|
||||
// - Accepts X-Dev-ClientId header (development)
|
||||
app.UseMiddleware<MultiProviderAuthMiddleware>();
|
||||
|
||||
// Standard middleware
|
||||
app.UseAuthorization();
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
Reference in New Issue
Block a user