|
| 1 | +// Licensed to Elasticsearch B.V under one or more agreements. |
| 2 | +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. |
| 3 | +// See the LICENSE file in the project root for more information |
| 4 | + |
| 5 | +using Elastic.Documentation.Api.Infrastructure; |
| 6 | +using Elastic.Documentation.Api.Infrastructure.OpenTelemetry; |
| 7 | +using Elastic.Documentation.Configuration.Assembler; |
| 8 | +using Elastic.Documentation.ServiceDefaults; |
| 9 | + |
| 10 | +try |
| 11 | +{ |
| 12 | + var builder = WebApplication.CreateSlimBuilder(args); |
| 13 | + _ = builder.AddDocumentationServiceDefaults(ref args, (s, p) => |
| 14 | + { |
| 15 | + _ = s.AddSingleton(AssemblyConfiguration.Create(p)); |
| 16 | + }); |
| 17 | + |
| 18 | + _ = builder.AddDocsApiOpenTelemetry(); |
| 19 | + |
| 20 | + // Configure Kestrel to listen on port 8080 (standard container port) |
| 21 | + _ = builder.WebHost.ConfigureKestrel(serverOptions => |
| 22 | + { |
| 23 | + serverOptions.ListenAnyIP(8080); |
| 24 | + }); |
| 25 | + |
| 26 | + var environment = Environment.GetEnvironmentVariable("ENVIRONMENT"); |
| 27 | + Console.WriteLine($"Docs Environment: {environment}"); |
| 28 | + |
| 29 | + builder.Services.AddElasticDocsApiUsecases(environment); |
| 30 | + var app = builder.Build(); |
| 31 | + |
| 32 | + if (app.Environment.IsDevelopment()) |
| 33 | + _ = app.UseDeveloperExceptionPage(); |
| 34 | + |
| 35 | + // Health check endpoint for load balancer target groups |
| 36 | + _ = app.MapGet("/health", () => Results.Ok(new { status = "healthy" })); |
| 37 | + |
| 38 | + var v1 = app.MapGroup("/docs/_api/v1"); |
| 39 | + |
| 40 | + var mapOtlpEndpoints = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]); |
| 41 | + v1.MapElasticDocsApiEndpoints(mapOtlpEndpoints); |
| 42 | + Console.WriteLine("API endpoints mapped"); |
| 43 | + |
| 44 | + Console.WriteLine("Application startup completed successfully"); |
| 45 | + app.Run(); |
| 46 | +} |
| 47 | +catch (Exception ex) |
| 48 | +{ |
| 49 | + Console.WriteLine($"FATAL ERROR during startup: {ex}"); |
| 50 | + Console.WriteLine($"Exception type: {ex.GetType().Name}"); |
| 51 | + Console.WriteLine($"Stack trace: {ex.StackTrace}"); |
| 52 | + throw; |
| 53 | +} |
| 54 | + |
| 55 | +// Make the Program class accessible for integration testing |
| 56 | +#pragma warning disable ASP0027 |
| 57 | +public partial class Program { } |
| 58 | +#pragma warning restore ASP0027 |
0 commit comments