102 lines
3.8 KiB
C#
102 lines
3.8 KiB
C#
using GoogleApi.Configuration;
|
|
using GoogleApi.Security;
|
|
using GoogleApi.Services;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// ============================================================
|
|
// CRITICAL: Explicit port binding for Azure Container Apps
|
|
// ============================================================
|
|
var port = Environment.GetEnvironmentVariable("PORT") ?? "8080";
|
|
builder.WebHost.UseUrls($"http://0.0.0.0:{port}");
|
|
|
|
// ============================================================
|
|
// Configuration
|
|
// ============================================================
|
|
|
|
// Bind GoogleAds configuration section
|
|
// Values can be overridden by environment variables:
|
|
// GoogleAds__EnableRealApi=true
|
|
// GoogleAds__DeveloperToken=xxx
|
|
// GoogleAds__OAuth__ClientId=xxx
|
|
// etc.
|
|
builder.Services.Configure<GoogleAdsConfig>(
|
|
builder.Configuration.GetSection(GoogleAdsConfig.SectionName));
|
|
|
|
// Log startup info
|
|
var googleConfig = builder.Configuration.GetSection(GoogleAdsConfig.SectionName).Get<GoogleAdsConfig>();
|
|
Console.WriteLine("===========================================");
|
|
Console.WriteLine($"[GoogleApi] Starting...");
|
|
Console.WriteLine($"[GoogleApi] Port: {port}");
|
|
Console.WriteLine($"[GoogleApi] Environment: {builder.Environment.EnvironmentName}");
|
|
Console.WriteLine($"[GoogleApi] GOOGLE_INTERNAL_KEY set: {!string.IsNullOrEmpty(builder.Configuration["InternalKey"] ?? Environment.GetEnvironmentVariable("GOOGLE_INTERNAL_KEY"))}");
|
|
Console.WriteLine($"[GoogleApi] Real API Enabled: {googleConfig?.EnableRealApi ?? false}");
|
|
Console.WriteLine($"[GoogleApi] API Version: {googleConfig?.ApiVersion ?? "not configured"}");
|
|
Console.WriteLine($"[GoogleApi] Developer Token Set: {!string.IsNullOrEmpty(googleConfig?.DeveloperToken)}");
|
|
Console.WriteLine("===========================================");
|
|
|
|
// ============================================================
|
|
// Services
|
|
// ============================================================
|
|
builder.Services.AddControllers();
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
builder.Services.AddSwaggerGen(c =>
|
|
{
|
|
c.SwaggerDoc("v1", new() { Title = "GoogleApi Provider", Version = "v1" });
|
|
});
|
|
|
|
// Core services
|
|
builder.Services.AddSingleton<GoogleAdsClientFactory>();
|
|
builder.Services.AddSingleton<GoogleAdsService>();
|
|
|
|
// Auth filter for internal calls from Gateway
|
|
builder.Services.AddScoped<InternalAuthFilter>();
|
|
|
|
// ============================================================
|
|
// Build & Configure
|
|
// ============================================================
|
|
var app = builder.Build();
|
|
|
|
Console.WriteLine("[GoogleApi] App built, configuring pipeline...");
|
|
|
|
// Always enable Swagger (helpful for debugging)
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI();
|
|
|
|
app.UseRouting();
|
|
app.MapControllers();
|
|
|
|
// Root health check
|
|
app.MapGet("/", () => Results.Ok(new
|
|
{
|
|
service = "GoogleApi",
|
|
status = "healthy",
|
|
timestamp = DateTimeOffset.UtcNow
|
|
}));
|
|
|
|
// Detailed health check with config status
|
|
app.MapGet("/health", (IConfiguration config) =>
|
|
{
|
|
var googleConfig = config.GetSection(GoogleAdsConfig.SectionName).Get<GoogleAdsConfig>();
|
|
|
|
return Results.Ok(new
|
|
{
|
|
service = "GoogleApi",
|
|
status = "healthy",
|
|
timestamp = DateTimeOffset.UtcNow,
|
|
config = new
|
|
{
|
|
realApiEnabled = googleConfig?.EnableRealApi ?? false,
|
|
apiVersion = googleConfig?.ApiVersion ?? "not configured",
|
|
developerTokenSet = !string.IsNullOrEmpty(googleConfig?.DeveloperToken),
|
|
oauthConfigured = !string.IsNullOrEmpty(googleConfig?.OAuth?.ClientId),
|
|
defaultLoginCustomerId = googleConfig?.DefaultLoginCustomerId ?? "(not set)"
|
|
}
|
|
});
|
|
});
|
|
|
|
Console.WriteLine("[GoogleApi] Pipeline configured, starting listener...");
|
|
Console.WriteLine($"[GoogleApi] Listening on http://0.0.0.0:{port}");
|
|
|
|
app.Run();
|