first commit

This commit is contained in:
2025-11-01 19:18:39 +10:30
commit d1d2c9f41e
26 changed files with 1052 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
using TinfoilVibeServer.Middleware;
using TinfoilVibeServer.Services;
var builder = WebApplication.CreateBuilder(args);
// -----------------------------------------------------
// 1. Register AuthStore as a singleton
// -----------------------------------------------------
builder.Services.AddSingleton<AuthStore>();
// -----------------------------------------------------
// 2. Snapshot + other services (unchanged)
// -----------------------------------------------------
builder.Services.AddSingleton<SnapshotService>();
// … any other services you already have
var app = builder.Build();
// -----------------------------------------------------
// 3. Apply authentication middleware *before* the
// snapshot endpoints. This guarantees all routes
// are protected.
// -----------------------------------------------------
app.UseMiddleware<BasicAuthMiddleware>();
// -----------------------------------------------------
// 4. Existing endpoints unchanged
// -----------------------------------------------------
app.MapGet("/", () => Results.Redirect("/index.tfl"));
app.MapGet("/index.tfl", async context =>
{
var jsonPath = Path.Combine(AppContext.BaseDirectory, "index.tfl");
context.Response.ContentType = "application/json";
await context.Response.WriteAsync(await File.ReadAllTextAsync(jsonPath));
});
app.MapGet("/debug", () => new SnapshotService(builder.Configuration).GetSnapshot());
app.MapGet("/stream/{*relativePath}", async context =>
{
// … (unchanged streaming logic same as before)
});
app.Run();