using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.ResponseCompression; using System.Diagnostics; using System.IO.Compression; using System.Text.Json.Serialization; using WebApplication1.Controllers; namespace WebApplication1; public class Program { public static void Main(string[] args) { #if DEBUG if (Debugger.IsAttached) { var sourcePath = Path.Combine(AppContext.BaseDirectory, "../../../Source"); Process.Start(new ProcessStartInfo { FileName = "cmd.exe", Arguments = $"/k \"cd /d \"{sourcePath}\" && npm run dev:vite\"", UseShellExecute = true }); Thread.Sleep(1000); } #endif var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddSingleton(); builder.Services .AddControllers((options) => { options.CacheProfiles.Add("Default", new CacheProfile { Duration = 2592000, Location = ResponseCacheLocation.Any, NoStore = false }); options.CacheProfiles.Add("NoCache", new CacheProfile { Location = ResponseCacheLocation.None, NoStore = true }); if (!builder.Environment.IsDevelopment()) { options.Filters.Add(); } }) .AddJsonOptions(options => { options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; }); builder.Services .AddResponseCompression(options => { options.Providers.Add(); options.Providers.Add(); options.MimeTypes = ["application/json"]; options.EnableForHttps = true; }) .Configure(options => { options.Level = CompressionLevel.Optimal; }) .AddResponseCaching(); builder.WebHost.UseIIS(); var app = builder.Build(); app.UseStaticFiles(); #if DEBUG app.UseDeveloperExceptionPage(); #endif // Configure the HTTP request pipeline. app.UseRouting(); app.UseAuthorization(); app.UseResponseCompression(); app.UseResponseCaching(); app.MapControllers(); app.Run(); } }