using Microsoft.AspNetCore.Authentication.Cookies; using MistoxWebsite.Server.Controllers; using MistoxWebsite.Server.Controllers.Payment; using MistoxWebsite.Server.Services; using MistoxWebsite.Server.Services.DatabaseService; using Stripe; var builder = WebApplication.CreateBuilder(args); // Disable null warnings becuse string.IsNullOrEmpty checks for NULL or Empty #pragma warning disable CS8600 #pragma warning disable CS8604 // Database Service string? _dbserver = Environment.GetEnvironmentVariable("MySQLServer"); string dbserver = !string.IsNullOrEmpty(_dbserver) ? _dbserver : "localhost"; string? _dbuser = Environment.GetEnvironmentVariable("MySQLUser"); string dbUser = !string.IsNullOrEmpty(_dbuser) ? _dbuser : "root"; string? _dbdatabase = Environment.GetEnvironmentVariable("MySQLDatabase"); string dbdatabase = !string.IsNullOrEmpty(_dbdatabase) ? _dbdatabase : "mistox"; string? _dbpass = Environment.GetEnvironmentVariable("MySQLPass"); string dbPass = !string.IsNullOrEmpty(_dbpass) ? _dbpass : ""; string connStr = "server=" + dbserver + ";user=" + dbUser + ";database=" + dbdatabase + ";password=" + dbPass + ";port=3306;"; DatabaseService databaseService = new DatabaseService( connectionString: connStr ); builder.Services.Add( new ServiceDescriptor( typeof( DatabaseService ), databaseService ) ); // Email Service string? _eServer = Environment.GetEnvironmentVariable("EmailServer"); string EmailServer = !string.IsNullOrEmpty(_eServer) ? _eServer : "smtp.gmail.com"; string? _ePort = Environment.GetEnvironmentVariable("EmailPort"); int EmailPort = !string.IsNullOrEmpty(_ePort) ? Convert.ToInt32(_ePort) : 587; string? _eAddress = Environment.GetEnvironmentVariable("EmailAddress"); string EmailAddress = !string.IsNullOrEmpty(_eAddress) ? _eAddress : ""; string? _ePassword = Environment.GetEnvironmentVariable("EmailPassword"); string EmailPassword = !string.IsNullOrEmpty(_ePassword) ? _ePassword : ""; EmailService Emailservice = new EmailService( EmailServer, EmailPort, EmailAddress, EmailPassword ); builder.Services.Add( new ServiceDescriptor( typeof( EmailService ), Emailservice )); // Payment Service string? PaymentService = Environment.GetEnvironmentVariable("PaymentService"); IPayment._PaymentType = (PaymentType)Enum.Parse(typeof(PaymentType), PaymentService, true); if (IPayment._PaymentType == PaymentType.StripeIntent) { string? StripeKey = Environment.GetEnvironmentVariable("StripeKey"); StripeConfiguration.ApiKey = StripeKey; string? StripeEndpointKey = Environment.GetEnvironmentVariable("StripeEndpointSecret"); IPayment._EndpointSecret = string.IsNullOrEmpty(StripeEndpointKey) ? "" : StripeEndpointKey ; } // Authentication Service builder.Services.AddAuthentication( options => { options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; } ).AddCookie(options => { options.Cookie.HttpOnly = true; options.Cookie.SecurePolicy = CookieSecurePolicy.Always; options.Cookie.SameSite = SameSiteMode.Strict; options.LoginPath = "/account/login"; options.LogoutPath = "/account/logout"; options.SlidingExpiration = true; }); builder.Services.AddCors( o => o.AddDefaultPolicy( builder => { builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader(); // No CORS } ) ); // Pages Service builder.Services.AddControllers(); builder.Services.AddRazorPages(); var app = builder.Build(); // Configure the HTTP request pipeline. if( !app.Environment.IsDevelopment() ) { app.UseHsts(); } app.UseDefaultFiles(); app.UseStaticFiles(); app.UseCors(); app.UseRouting(); app.UseAuthentication(); app.MapControllers(); app.MapFallbackToFile("index.html"); app.Run();