using StorageServer.IO; using StorageServer.Models; namespace StorageServer; public class Program { public static void Main(string[] args) { const string settingPath = "storage_config.xml"; const string allowOrigins = "_storageserver_allow_origin"; if (!File.Exists(settingPath)) { XmlReader.Save(settingPath, new SettingModel() { DBFilePath = "files.db", SavePath = "saves", }); } SettingModel setting = XmlReader.Read(settingPath); DatabaseFactory factory = new DatabaseFactory(setting.DBFilePath); StorageProvider provider = new StorageProvider(setting.SavePath); var builder = WebApplication.CreateBuilder(args); builder.Services.AddSingleton(factory); builder.Services.AddSingleton(provider); // Add services to the container. builder.Services.AddControllersWithViews(); builder.Services.AddCors(options => { options.AddPolicy(allowOrigins, policy => { policy.AllowAnyOrigin(); policy.AllowAnyHeader(); policy.AllowAnyMethod(); }); }); var app = builder.Build(); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseCors(allowOrigins); app.UseAuthorization(); app.MapControllerRoute( name: "default", pattern: "{controller=File}/{action=Read}/{FileId?}"); app.Run(); factory.Dispose(); } }