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 <noreply@anthropic.com>
This commit is contained in:
parent
9ca50a1da8
commit
0596e6db47
1 changed files with 19 additions and 5 deletions
|
|
@ -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(
|
||||
"<p>Sanity Studio has not been built. Check the Docker build logs.</p>",
|
||||
{ status: 503, headers: { "Content-Type": "text/html" } }
|
||||
);
|
||||
}
|
||||
|
||||
return new Response(readFileSync(indexPath, "utf-8"), {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "text/html; charset=utf-8" },
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue