Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
fix(server): answer a failed static precondition with 412 and a bad range with 416 instead of 500
nirholas5b8f5b31dce3
diff --git a/server/index.mjs b/server/index.mjsindex c7c63d981..437a5d863 100644--- a/server/index.mjs+++ b/server/index.mjs@@ -333,8 +333,19 @@ function serveFile(req, res, file, headers, status) {return new Promise((resolvePromise) => {res.sendFile(rel, { dotfiles, root: DIST_ROOT }, (err) => {if (err && !res.headersSent) {- console.error(`[static] ${req.method} ${req.url} → ${file} failed:`, err.message);- res.status(500).end();+ // send() reports a request it cannot honour with that request's own+ // 4xx: 412 when an If-Match / If-Unmodified-Since precondition fails+ // (Cloud CDN revalidating a fill after a deploy changed the file), 416+ // for an unsatisfiable range. Those are answers, not server faults;+ // flattening them to 500 put /robots.txt and /hdri/studio.hdr in the+ // 5xx log 14 times in a week and handed the edge an error to cache.+ const status = Number(err.status || err.statusCode);+ if (status >= 400 && status < 500) {+ res.status(status).end();+ } else {+ console.error(`[static] ${req.method} ${req.url} → ${file} failed:`, err.message);+ res.status(500).end();+ }}resolvePromise();});diff --git a/tests/server-static-conditional.test.js b/tests/server-static-conditional.test.jsnew file mode 100644index 000000000..93064b477--- /dev/null+++ b/tests/server-static-conditional.test.js@@ -0,0 +1,52 @@+import { describe, it, expect, beforeAll, afterAll } from 'vitest';+import { mkdirSync, writeFileSync, rmSync } from 'node:fs';+import { fileURLToPath } from 'node:url';+import { startTestServer } from './helpers/test-server.js';++// A static file whose conditional request cannot be honoured must answer with+// the request's own status, never 500. Production 2026-10-08: Cloud CDN+// revalidated /robots.txt and /hdri/studio.hdr with a precondition the freshly+// deployed file no longer met; send() raised 412 Precondition Failed and the+// static handler flattened it to a 500 (14 in a week, all logged as server+// faults and handed to the edge as errors).++const dir = fileURLToPath(new URL('../dist/__static-conditional-test__/', import.meta.url));+const FILE = '/__static-conditional-test__/probe.txt';++let BASE;+let server;++beforeAll(async () => {+ mkdirSync(dir, { recursive: true });+ writeFileSync(`${dir}probe.txt`, 'static conditional probe\n');+ server = await startTestServer();+ BASE = server.base;+}, 60000);++afterAll(() => {+ server?.close();+ rmSync(dir, { recursive: true, force: true });+});++describe('static conditional requests', () => {+ it('serves the file normally', async () => {+ const res = await fetch(`${BASE}${FILE}`);+ expect(res.status).toBe(200);+ expect(await res.text()).toBe('static conditional probe\n');+ });++ it('answers 412, not 500, when If-Match does not match', async () => {+ const res = await fetch(`${BASE}${FILE}`, { headers: { 'if-match': '"not-this-etag"' } });+ expect(res.status).toBe(412);+ });++ it('answers 412, not 500, when the file changed after If-Unmodified-Since', async () => {+ const res = await fetch(`${BASE}${FILE}`, { headers: { 'if-unmodified-since': 'Thu, 01 Jan 1970 00:00:00 GMT' } });+ expect(res.status).toBe(412);+ });++ it('answers 416 for a range past the end of the file', async () => {+ const res = await fetch(`${BASE}${FILE}`, { headers: { range: 'bytes=999999-' } });+ expect(res.status).toBe(416);+ });+});