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" }, + }); +};