Fix: CORS header before upstream await + movement debug prints

CORS: Access-Control-Allow-Origin must be set before the CDN GetAsync
call so it is present even if the upstream throws (ASP.NET Core exception
handling resets responses, dropping headers set after an exception).
Added try/catch to return 502 cleanly on upstream failures.

Debug: [Move] prints in _play_move_animations and _schedule_rebuild to
diagnose why movement animation appears instant.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-03-15 20:42:09 -04:00
co-authored by Claude Happy
parent e254cd8ee8
commit a86675b0c9
2 changed files with 26 additions and 6 deletions
+15 -5
View File
@@ -210,14 +210,24 @@ if (IsEnabled("auth"))
app.MapHealthChecks("/health");
// CDN asset proxy: adds CORS so browser web clients can fetch models/assets.
// Access-Control-Allow-Origin is set before the upstream await so it is
// present on error responses too (browsers suppress CORS errors otherwise).
app.MapGet("/cdn/{**path}", async (string path, HttpContext httpCtx, IHttpClientFactory factory) =>
{
using var up = await factory.CreateClient("cdn").GetAsync($"{cdnProxyBase}/{path}");
httpCtx.Response.Headers["Access-Control-Allow-Origin"] = "*";
httpCtx.Response.StatusCode = (int)up.StatusCode;
httpCtx.Response.ContentType =
up.Content.Headers.ContentType?.MediaType ?? "application/octet-stream";
await up.Content.CopyToAsync(httpCtx.Response.Body);
try
{
using var up = await factory.CreateClient("cdn").GetAsync($"{cdnProxyBase}/{path}");
httpCtx.Response.StatusCode = (int)up.StatusCode;
httpCtx.Response.ContentType =
up.Content.Headers.ContentType?.MediaType ?? "application/octet-stream";
await up.Content.CopyToAsync(httpCtx.Response.Body);
}
catch
{
if (!httpCtx.Response.HasStarted)
httpCtx.Response.StatusCode = 502;
}
});
// ── RUN ───────────────────────────────────────────────────────────────────────