Removed Immediate.Apis, Added AOT Testing Scripts.
This commit is contained in:
+5
-67
@@ -1,9 +1,11 @@
|
||||
using Htmx.ApiDemo;
|
||||
using Htmx.ApiDemo.Data;
|
||||
using Immediate.Handlers;
|
||||
using Htmx.ApiDemo.Templates;
|
||||
using Microsoft.AspNetCore.Antiforgery;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization;
|
||||
using MongoDB.Bson.Serialization.Serializers;
|
||||
@@ -59,13 +61,10 @@ builder.Services
|
||||
});
|
||||
|
||||
builder.Services.AddScoped<IPasswordHasher<AppUser>, PasswordHasher<AppUser>>();
|
||||
builder.Services.AddScoped<AuthService>();
|
||||
builder.Services.AddScoped<AppAuthService>();
|
||||
|
||||
// ── App services ──────────────────────────────────────────────────────────
|
||||
builder.Services.AddHttpContextAccessor();
|
||||
builder.Services
|
||||
.AddHtmxApiDemoBehaviors()
|
||||
.AddHtmxApiDemoHandlers();
|
||||
builder.Services.AddOpenApi();
|
||||
builder.Services.AddAuthorization();
|
||||
|
||||
@@ -83,67 +82,6 @@ app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
app.UseAntiforgery();
|
||||
|
||||
// ── Guard: redirect unauthenticated users to /login ───────────────────────
|
||||
app.Use(async (context, next) =>
|
||||
{
|
||||
var path = context.Request.Path.Value ?? "";
|
||||
bool isPublic = path.StartsWith("/login", StringComparison.OrdinalIgnoreCase)
|
||||
|| path.StartsWith("/register", StringComparison.OrdinalIgnoreCase)
|
||||
|| path.StartsWith("/logout", StringComparison.OrdinalIgnoreCase)
|
||||
|| path.StartsWith("/css/", StringComparison.OrdinalIgnoreCase)
|
||||
|| path.StartsWith("/js/", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
if (!isPublic && context.User.Identity?.IsAuthenticated != true)
|
||||
{
|
||||
context.Response.Redirect("/login");
|
||||
return;
|
||||
}
|
||||
|
||||
await next();
|
||||
});
|
||||
|
||||
// Explicit MapGet/MapPost with explicit lambda return type ValueTask<IResult>.
|
||||
// The explicit return type annotation lets RequestDelegateGenerator see IResult
|
||||
// directly (without needing to resolve the generated Handler.HandleAsync type),
|
||||
// so it emits `await result.ExecuteAsync(httpContext)` instead of JSON serialization.
|
||||
app.MapGet("/", static ValueTask<IResult> (
|
||||
[AsParameters] Htmx.ApiDemo.Templates.GetIndexHandler.Command cmd,
|
||||
Htmx.ApiDemo.Templates.GetIndexHandler.Handler handler,
|
||||
CancellationToken token) => handler.HandleAsync(cmd, token));
|
||||
|
||||
app.MapGet("/greet/{username}/{count?}/{id?}", static ValueTask<IResult> (
|
||||
[AsParameters] Htmx.ApiDemo.Templates.GetGreetingHandler.Query query,
|
||||
Htmx.ApiDemo.Templates.GetGreetingHandler.Handler handler,
|
||||
CancellationToken token) => handler.HandleAsync(query, token));
|
||||
|
||||
app.MapGet("/login", static ValueTask<IResult> (
|
||||
[AsParameters] Htmx.ApiDemo.Templates.GetLoginHandler.Query query,
|
||||
Htmx.ApiDemo.Templates.GetLoginHandler.Handler handler,
|
||||
CancellationToken token) => handler.HandleAsync(query, token));
|
||||
|
||||
app.MapPost("/login", static ValueTask<IResult> (
|
||||
[AsParameters] Htmx.ApiDemo.Templates.PostLoginHandler.Command cmd,
|
||||
Htmx.ApiDemo.Templates.PostLoginHandler.Handler handler,
|
||||
CancellationToken token) => handler.HandleAsync(cmd, token));
|
||||
|
||||
app.MapGet("/register", static ValueTask<IResult> (
|
||||
[AsParameters] Htmx.ApiDemo.Templates.GetRegisterHandler.Query query,
|
||||
Htmx.ApiDemo.Templates.GetRegisterHandler.Handler handler,
|
||||
CancellationToken token) => handler.HandleAsync(query, token));
|
||||
|
||||
app.MapPost("/register", static ValueTask<IResult> (
|
||||
[AsParameters] Htmx.ApiDemo.Templates.PostRegisterHandler.Command cmd,
|
||||
Htmx.ApiDemo.Templates.PostRegisterHandler.Handler handler,
|
||||
CancellationToken token) => handler.HandleAsync(cmd, token));
|
||||
|
||||
app.MapPost("/logout", static ValueTask<IResult> (
|
||||
[AsParameters] Htmx.ApiDemo.Templates.PostLogoutHandler.Command cmd,
|
||||
Htmx.ApiDemo.Templates.PostLogoutHandler.Handler handler,
|
||||
CancellationToken token) => handler.HandleAsync(cmd, token));
|
||||
|
||||
app.MapGet("/ui-demo", static ValueTask<IResult> (
|
||||
[AsParameters] Htmx.ApiDemo.Templates.GetUiDemoHandler.Query query,
|
||||
Htmx.ApiDemo.Templates.GetUiDemoHandler.Handler handler,
|
||||
CancellationToken token) => handler.HandleAsync(query, token));
|
||||
app.MapHtmxRoutes();
|
||||
|
||||
app.Run();
|
||||
Reference in New Issue
Block a user