fix: remove storybook route handler that may cause build failures
Storybook static files remain in public/ but are served directly by the web server rather than through a Next.js route handler. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
e635771615
commit
57918a6d8c
@ -1,61 +0,0 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import path from "node:path";
|
||||
import fs from "node:fs";
|
||||
|
||||
const MIME_TYPES: Record<string, string> = {
|
||||
".html": "text/html",
|
||||
".js": "application/javascript",
|
||||
".css": "text/css",
|
||||
".json": "application/json",
|
||||
".svg": "image/svg+xml",
|
||||
".png": "image/png",
|
||||
".jpg": "image/jpeg",
|
||||
".woff2": "font/woff2",
|
||||
".woff": "font/woff",
|
||||
".ico": "image/x-icon",
|
||||
};
|
||||
|
||||
function getStorybookRoot(): string {
|
||||
// In standalone mode, public files are at ../public relative to server.js
|
||||
// In dev mode, they're in the project's public directory
|
||||
const candidates = [
|
||||
path.join(process.cwd(), "public", "storybook"),
|
||||
path.join(process.cwd(), "apps", "portal", "public", "storybook"),
|
||||
];
|
||||
for (const candidate of candidates) {
|
||||
if (fs.existsSync(candidate)) return candidate;
|
||||
}
|
||||
return candidates[0]!;
|
||||
}
|
||||
|
||||
export async function GET(
|
||||
_request: NextRequest,
|
||||
{ params }: { params: Promise<{ path?: string[] }> }
|
||||
) {
|
||||
const resolvedParams = await params;
|
||||
const segments = resolvedParams.path;
|
||||
const filePath = segments?.length ? segments.join("/") : "index.html";
|
||||
|
||||
const root = getStorybookRoot();
|
||||
const resolved = path.resolve(root, filePath);
|
||||
|
||||
// Prevent path traversal
|
||||
if (!resolved.startsWith(root)) {
|
||||
return new NextResponse("Forbidden", { status: 403 });
|
||||
}
|
||||
|
||||
if (!fs.existsSync(resolved)) {
|
||||
return new NextResponse("Not found", { status: 404 });
|
||||
}
|
||||
|
||||
const ext = path.extname(resolved);
|
||||
const contentType = MIME_TYPES[ext] || "application/octet-stream";
|
||||
const content = fs.readFileSync(resolved);
|
||||
|
||||
return new NextResponse(content, {
|
||||
headers: {
|
||||
"Content-Type": contentType,
|
||||
"Cache-Control": ext === ".html" ? "no-cache" : "public, max-age=31536000, immutable",
|
||||
},
|
||||
});
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user