From 0596e6db473bcb972734f9373c1f1c7649d0e513 Mon Sep 17 00:00:00 2001 From: Calum Muir Date: Sun, 7 Jun 2026 12:27:21 +0000 Subject: [PATCH] Fix infinite redirect on /studio by serving index.html directly [...path] catches /studio itself (empty rest param), causing a redirect loop. Now reads and returns index.html content for all /studio/* paths; static assets are still served before this route fires. Co-Authored-By: Claude Sonnet 4.6 --- src/pages/studio/[...path].ts | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/pages/studio/[...path].ts b/src/pages/studio/[...path].ts index f94649a..748be75 100644 --- a/src/pages/studio/[...path].ts +++ b/src/pages/studio/[...path].ts @@ -1,7 +1,21 @@ import type { APIRoute } from "astro"; +import { readFileSync, existsSync } from "fs"; +import { join } from "path"; -// Redirect deep studio links (e.g. /studio/desk/post) back to /studio so the -// SPA can boot and handle its own routing. Static assets under /studio/assets/* -// are served before this route ever fires. -export const GET: APIRoute = () => - new Response(null, { status: 302, headers: { Location: "/studio" } }); +// Serve the studio SPA for all /studio/* paths (including /studio itself). +// Static assets under /studio/assets/* are served before this route fires. +export const GET: APIRoute = () => { + const indexPath = join(process.cwd(), "dist/client/studio/index.html"); + + if (!existsSync(indexPath)) { + return new Response( + "

Sanity Studio has not been built. Check the Docker build logs.

", + { status: 503, headers: { "Content-Type": "text/html" } } + ); + } + + return new Response(readFileSync(indexPath, "utf-8"), { + status: 200, + headers: { "Content-Type": "text/html; charset=utf-8" }, + }); +};