using Microsoft.AspNetCore.Authentication.Cookies; using MistoxWebsite.Server.Controllers; 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 : "oasv34$8gpv023dd"; string connStr = "server=" + dbserver + ";user=" + dbUser + ";database=" + dbdatabase + ";password=" + dbPass + ";port=3306;"; DatabaseService databaseService = new DatabaseService( connectionString: connStr ); await ProductController.HotReload( databaseService ); builder.Services.Add( new ServiceDescriptor( typeof( DatabaseService ), databaseService ) ); // Email Service string? _eServer = Environment.GetEnvironmentVariable("EmailServer"); string EmailServer = !string.IsNullOrEmpty(_eServer) ? _eServer : "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 : "no-reply@mistox.com"; 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? StripeKey = Environment.GetEnvironmentVariable("StripeKey"); StripeConfiguration.ApiKey = StripeKey; // Authentication Service builder.Services.AddAuthentication( options => { options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; } ).AddCookie(); builder.Services.AddCors( o => o.AddDefaultPolicy( builder => { builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader(); } ) ); // Pages Service builder.Services.AddControllers(); builder.Services.AddRazorPages(); var app = builder.Build(); // Configure the HTTP request pipeline. if( app.Environment.IsDevelopment() ) { app.UseWebAssemblyDebugging(); } else { app.UseHsts(); } app.UseBlazorFrameworkFiles(); app.UseStaticFiles(); app.UseCors(); app.UseAuthentication(); app.MapControllers(); app.MapFallbackToFile("index.html"); app.Run();