From acdeb0ede9ba468e2755b7a2024211006aa064c7 Mon Sep 17 00:00:00 2001 From: "Satsuki Akiba (aider)" Date: Wed, 4 Jun 2025 10:43:07 +0900 Subject: [PATCH] refactor: serve static Next.js files instead of SSR --- server.ts | 49 +++++++++++-------------------------------------- 1 file changed, 11 insertions(+), 38 deletions(-) diff --git a/server.ts b/server.ts index 52db5e6..ce1f8dd 100644 --- a/server.ts +++ b/server.ts @@ -140,46 +140,19 @@ serve({ } } - // Next.jsのSSRを処理 + // Next.jsの静的ファイルを提供するディレクトリのパスを指定 + const indexPath = path.join(frontendBuildDir, "server", "pages", "index.html"); + + // 通常のリクエストは静的ファイルで処理 try { - // Next.jsのページレンダリング - const app = require("./frontend/src/app"); - - // ページコンポーネントを取得 - const pageComponent = app.default || app.Home || app; - - // React要素を作成 - const element = React.createElement(pageComponent); - - // React DOMを使用してHTMLを生成 - const ReactDOMServer = require("react-dom/server"); - const html = ReactDOMServer.renderToString(element); - - // 完全なHTMLドキュメントを構築 - const htmlTemplate = ` - - - - - - ポッドキャスト管理画面 - - - - - - - -
${html}
- - - `.trim(); - - return new Response(htmlTemplate, { - headers: { "Content-Type": "text/html; charset=utf-8" } - }); + const file = Bun.file(indexPath); + if (await file.exists()) { + return new Response(file, { + headers: { "Content-Type": "text/html; charset=utf-8" } + }); + } } catch (e) { - console.error("Error rendering Next.js app:", e); + console.error("Error serving index.html:", e); } return new Response("Not Found", { status: 404 });