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(routing): 404 an unknown docs slug instead of serving an empty shell
nirholas50fd95ae1fde
diff --git a/scripts/inject-seo-meta.mjs b/scripts/inject-seo-meta.mjsindex dd53a9a05..093f5b775 100644--- a/scripts/inject-seo-meta.mjs+++ b/scripts/inject-seo-meta.mjs@@ -79,9 +79,12 @@ function buildRouter(vercel) {for (const r of routes) {if (!r || typeof r.src !== 'string' || typeof r.dest !== 'string') continue;if (r.methods && !r.methods.includes('GET')) continue;- // Only care about routes that land on a static .html file.+ // Only care about routes that land on a static .html file. A dest may carry+ // `$1`-style backreferences (`/docs/(.*)` → `/docs/$1`), so whether it ends+ // in .html is only knowable once the capture is substituted at match time.const destPath = r.dest.split('?')[0];- if (!destPath.endsWith('.html')) continue;+ const templated = /\$\d/.test(destPath);+ if (!templated && !destPath.endsWith('.html')) continue;if (ERROR_DOCS.has(destPath)) continue;let re;try {@@ -94,15 +97,23 @@ function buildRouter(vercel) {return out;}+// Where a router `dest` can live on disk, most specific first. The repo root is+// last so a `pages/` or `public/` file always wins; it exists because a few+// shells are authored outside both (the docs SPA is `docs/index.html`, which+// serves /docs and every /docs/<topic> route it client-routes).+const DEST_BASES = ['pages', 'public', '.'];+function resolveFile(p, router) {// 1) vercel.json router match.for (const { re, dest } of router) {- if (re.test(p)) {- const rel = dest.replace(/^\//, '');- for (const base of ['pages', 'public']) {- const f = path.join(ROOT, base, rel);- if (existsSync(f)) return f;- }+ const m = re.exec(p);+ if (!m) continue;+ const expanded = dest.replace(/\$(\d)/g, (_, i) => m[Number(i)] ?? '');+ if (!expanded.endsWith('.html') || ERROR_DOCS.has(expanded)) continue;+ const rel = expanded.replace(/^\//, '');+ for (const base of DEST_BASES) {+ const f = path.join(ROOT, base, rel);+ if (existsSync(f)) return f;}}// 2) conventional fallbacks.diff --git a/server/index.mjs b/server/index.mjsindex f51d842d5..fb23316e8 100644--- a/server/index.mjs+++ b/server/index.mjs@@ -37,6 +37,7 @@ import path from 'node:path';import { pathToFileURL, fileURLToPath } from 'node:url';import { isSsrRoute, renderSsrPage } from './ssr-pages.mjs';import { hasSeoRoute, renderSeoHead } from './seo-head.mjs';+import { isMissingShellPage } from './shell-pages.mjs';import { hardenHeaderBag } from './csp-hashes.mjs';// Route resolution lives in its own module so the audit scripts// (scripts/audit-cron-liveness.mjs) exercise the SAME resolver production runs,@@ -412,7 +413,13 @@ app.use(async (req, res) => {// Filesystem phase (GET/HEAD only, like a static host).if (req.method === 'GET' || req.method === 'HEAD') {- const file = resolveStatic(currentPath);+ // /docs/* and /tutorials/* rewrite every slug to one shell, so a typo used+ // to answer 200 with an empty shell instead of a 404. When the article the+ // shell would fetch does not exist, this is not a page: serve whatever the+ // raw path names on disk (/docs/<dir>/index.html), and otherwise skip the+ // filesystem phase so the request lands on the designed 404 below.+ const shellMiss = isMissingShellPage(DIST_ROOT, currentPath, url.pathname);+ const file = shellMiss ? resolveStatic(url.pathname) : resolveStatic(currentPath);if (file) {// A few directory pages render their whole body from client JS, which// leaves crawlers and no-JS visitors an empty shell. For those routes wediff --git a/server/shell-pages.mjs b/server/shell-pages.mjsnew file mode 100644index 000000000..679b6e8e0--- /dev/null+++ b/server/shell-pages.mjs@@ -0,0 +1,67 @@+// Existence checks for shared-shell pages (/docs/*, /tutorials/*).+// ---------------------------------------------------------------------------+// Those two surfaces rewrite EVERY slug under them to a single HTML shell, so+// the route table alone cannot tell a real page from a typo: /docs/anything+// answered 200 with the shell, which then rendered a bare "Page not found."+// line and no way back into the product. A soft 404 like that gets indexed as+// a live page, and a reader who mistypes a doc URL hits a dead end.+//+// Both shells render one markdown article fetched from dist/docs, so that file+// IS the page's existence test:+//+// /docs/agent-runtime → dist/docs/agent-runtime.md+// /docs/agent-abilities/chapters/02-motion → dist/docs/agent-abilities/chapters/02-motion.md+// /tutorials/text-to-3d → dist/docs/tutorials/text-to-3d.md+//+// server/index.mjs consults this before serving a shell, so a slug with no+// article falls through to the designed /404.html with a real 404 status.++import { statSync } from 'node:fs';+import path from 'node:path';++// Rewrite dest → { request-path prefix the shell answers for, article root+// under dist/ }. Keyed on the dest rather than the request path so routes that+// resolve elsewhere before reaching the shell (/docs/world, /docs/walk/*,+// /docs/widgets) are never touched by this check.+const SHELLS = new Map([+ ['/docs/index.html', { prefix: '/docs/', articles: 'docs' }],+ ['/tutorial.html', { prefix: '/tutorials/', articles: 'docs/tutorials' }],+]);++// What a doc slug may look like: path segments of letters, digits, `-` and `_`+// (dist/docs holds both `agent-runtime` and `pumpfun-program/docs/CPI_README`).+// A dot is deliberately excluded, so `..` traversal and `foo.md` can never+// reach the filesystem probe below.+const ARTICLE_SLUG = /^[A-Za-z0-9][A-Za-z0-9_-]*(\/[A-Za-z0-9][A-Za-z0-9_-]*)*$/;++/**+ * Is this request a shared-shell page whose article does not exist?+ *+ * @param {string} distRoot absolute path to the built dist/ directory+ * @param {string} dest the path the route table rewrote to (e.g. /docs/index.html)+ * @param {string} pathname the ORIGINAL request path (e.g. /docs/agent-runtime)+ * @returns {boolean} true only for a shell page that has no article behind it+ */+export function isMissingShellPage(distRoot, dest, pathname) {+ const shell = SHELLS.get(dest);+ if (!shell || !pathname.startsWith(shell.prefix)) return false;++ let slug;+ try {+ slug = decodeURIComponent(pathname.slice(shell.prefix.length));+ } catch {+ return true; // malformed encoding can never name an article+ }+ slug = slug.replace(/\/+$/, '');+ if (!slug) return false; // the shell's own index page+ if (!ARTICLE_SLUG.test(slug)) return true;++ const articleRoot = path.join(distRoot, ...shell.articles.split('/'));+ const file = path.join(articleRoot, `${slug}.md`);+ if (!file.startsWith(articleRoot + path.sep)) return true; // defense in depth+ try {+ return !statSync(file).isFile();+ } catch {+ return true;+ }+}diff --git a/vercel.json b/vercel.jsonindex 0718d45a2..6b8075af1 100644--- a/vercel.json+++ b/vercel.json@@ -4212,11 +4212,7 @@"dest": "/docs-freshness.html"},{- "src": "/docs/([^./]+)/?",- "dest": "/docs/index.html"- },- {- "src": "/docs/tutorials/([^./]+)/?",+ "src": "/docs/([^.]+?)/?","dest": "/docs/index.html"},{@@ -4709,6 +4705,10 @@"src": "/api/swarms","dest": "/api/swarms"},+ {+ "src": "/api/x402/service/([^/?]+)",+ "dest": "/api/x402/service.js?slug=$1"+ },{"src": "/api/(.*)","dest": "/api/$1"@@ -5520,10 +5520,6 @@"src": "/play/ufo/","dest": "/play/ufo.html"},- {- "src": "/api/x402/service/([^/?]+)",- "dest": "/api/x402/service.js?slug=$1"- },{"src": "/api/x402/fact-check","dest": "/api/x402/fact-check.js"