using Server.Services; var builder = WebApplication.CreateBuilder(args); // Add services to the container builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "SharpCAT Server API", Version = "v1", Description = "ASP.NET Core Web API for CAT (Computer Aided Transceiver) control using SharpCAT library", Contact = new Microsoft.OpenApi.Models.OpenApiContact { Name = "SharpCAT Project" } }); // Include XML comments if available var xmlFilename = $"{System.Reflection.Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFilename); if (File.Exists(xmlPath)) { c.IncludeXmlComments(xmlPath); } }); // Register the serial communication service as a singleton // to maintain connection state across requests builder.Services.AddSingleton(); // Add CORS policy for cross-origin requests builder.Services.AddCors(options => { options.AddPolicy("AllowAll", policy => { policy.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader(); }); }); var app = builder.Build(); // Configure the HTTP request pipeline if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "SharpCAT Server API v1"); c.RoutePrefix = string.Empty; // Set Swagger UI at app's root }); } app.UseCors("AllowAll"); app.UseRouting(); app.MapControllers(); // Add a simple health check endpoint app.MapGet("/health", () => new { status = "healthy", timestamp = DateTime.UtcNow }) .WithName("HealthCheck") .WithOpenApi(); app.Run();