101 lines
3.1 KiB
C#
101 lines
3.1 KiB
C#
using HopFrame.Core.Services;
|
|
using HopFrame.Web;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using SpotiParty.Web;
|
|
using SpotiParty.Web.Components;
|
|
using SpotiParty.Web.Models;
|
|
using SpotiParty.Web.Services;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
builder.Configuration.AddEnvironmentVariables();
|
|
|
|
// Add services to the container.
|
|
builder.Services.AddRazorComponents()
|
|
.AddInteractiveServerComponents();
|
|
|
|
builder.AddServiceDefaults();
|
|
|
|
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
|
AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
|
|
|
|
builder.Services.AddHttpContextAccessor();
|
|
builder.Services.AddScoped<ClientSideStorage>();
|
|
builder.AddNpgsqlDbContext<DatabaseContext>("SpotiParty");
|
|
builder.Services.AddDbContextFactory<DatabaseContext>(options => {
|
|
options.UseNpgsql(builder.Configuration.GetConnectionString("SpotiParty"));
|
|
});
|
|
builder.Services.AddScoped<AuthorizationHandler>();
|
|
|
|
builder.Services.AddScoped<IHopFrameAuthHandler, DashboardAuthHandler>();
|
|
builder.Services.AddScoped<DashboardAuthHandler>();
|
|
builder.Services.AddScoped<EventsDashboardRepo>();
|
|
builder.Services.AddHopFrame(config => {
|
|
config.SetLoginPage("/login");
|
|
|
|
config.AddDbContext<DatabaseContext>(context => {
|
|
context.Table<User>(table => {
|
|
table
|
|
.SetViewPolicy(DashboardAuthHandler.AdminPolicy)
|
|
.SetCreatePolicy(DashboardAuthHandler.AdminPolicy)
|
|
.SetUpdatePolicy(DashboardAuthHandler.AdminPolicy)
|
|
.SetDeletePolicy(DashboardAuthHandler.AdminPolicy);
|
|
|
|
table.Property(u => u.RefreshToken)
|
|
.List(false)
|
|
.DisplayValue(false)
|
|
.SetEditable(false);
|
|
});
|
|
|
|
context.Table<Event>()
|
|
.SetDisplayName(Guid.NewGuid().ToString())
|
|
.Ignore(true);
|
|
});
|
|
|
|
config.AddCustomRepository<EventsDashboardRepo, Event, Guid>(e => e.Id, table => {
|
|
table.SetDisplayName("Events");
|
|
|
|
table.Property(e => e.Id)
|
|
.List(false)
|
|
.SetEditable(false)
|
|
.SetCreatable(false);
|
|
|
|
table.Property(e => e.Host)
|
|
.List(false)
|
|
.SetEditable(false)
|
|
.SetCreatable(false)
|
|
.SetDisplayedProperty(u => u.DisplayName);
|
|
|
|
table.ShowSearchSuggestions(false);
|
|
});
|
|
|
|
config.AddPlugin<AdminDashboardPlugin>();
|
|
});
|
|
|
|
var app = builder.Build();
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (!app.Environment.IsDevelopment()) {
|
|
app.UseExceptionHandler("/Error", createScopeForErrors: true);
|
|
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
|
app.UseHsts();
|
|
}
|
|
|
|
await using (var scope = app.Services.CreateAsyncScope()) {
|
|
var context = scope.ServiceProvider.GetRequiredService<DatabaseContext>();
|
|
await context.Database.MigrateAsync();
|
|
}
|
|
|
|
app.MapDefaultEndpoints();
|
|
|
|
app.UseStatusCodePagesWithReExecute("/not-found");
|
|
//app.UseHttpsRedirection();
|
|
|
|
app.UseAntiforgery();
|
|
|
|
app.MapStaticAssets();
|
|
app.MapRazorComponents<App>()
|
|
.AddInteractiveServerRenderMode()
|
|
.AddHopFramePages();
|
|
|
|
app.Run(); |