From 57918a6d8cb456b4987cd76f3aa3cf41f2399bef Mon Sep 17 00:00:00 2001 From: Temuulen Ankhbayar Date: Sat, 7 Mar 2026 17:36:41 +0900 Subject: [PATCH] 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 --- .../src/app/storybook/[[...path]]/route.ts | 61 ------------------- 1 file changed, 61 deletions(-) delete mode 100644 apps/portal/src/app/storybook/[[...path]]/route.ts diff --git a/apps/portal/src/app/storybook/[[...path]]/route.ts b/apps/portal/src/app/storybook/[[...path]]/route.ts deleted file mode 100644 index 4e089f8d..00000000 --- a/apps/portal/src/app/storybook/[[...path]]/route.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { NextRequest, NextResponse } from "next/server"; -import path from "node:path"; -import fs from "node:fs"; - -const MIME_TYPES: Record = { - ".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", - }, - }); -}