Rewrite studio asset paths from /static/ to /studio/static/ at serve time

Sanity v3 basePath only affects the SPA router, not Vite's build output.
The built index.html hardcodes /static/ so we rewrite on the way out.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Calum Muir 2026-06-07 12:55:01 +00:00
parent 847952228f
commit 8e2cd0b0d6

View file

@ -14,7 +14,13 @@ export const GET: APIRoute = () => {
); );
} }
return new Response(readFileSync(indexPath, "utf-8"), { // Rewrite absolute asset paths from /static/ to /studio/static/ so
// the studio's JS/CSS/icons load correctly when hosted at /studio.
const html = readFileSync(indexPath, "utf-8")
.replaceAll('="/static/', '="/studio/static/')
.replaceAll("='/static/", "='/studio/static/");
return new Response(html, {
status: 200, status: 200,
headers: { "Content-Type": "text/html; charset=utf-8" }, headers: { "Content-Type": "text/html; charset=utf-8" },
}); });