83 lines
3.3 KiB
C#
Executable File
83 lines
3.3 KiB
C#
Executable File
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 : "";
|
|
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 : "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? StripeKey = Environment.GetEnvironmentVariable("StripeKey");
|
|
StripeConfiguration.ApiKey = StripeKey;
|
|
|
|
// 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.UseWebAssemblyDebugging();
|
|
} else {
|
|
app.UseHsts();
|
|
}
|
|
|
|
app.UseBlazorFrameworkFiles();
|
|
app.UseStaticFiles();
|
|
|
|
app.UseCors();
|
|
|
|
app.UseAuthentication();
|
|
app.MapControllers();
|
|
|
|
app.MapFallbackToFile("index.html");
|
|
|
|
app.Run();
|