feat: migrate frontend to Next.js

This commit is contained in:
2025-06-04 09:08:32 +09:00
parent 25c771b90b
commit 1defdb8bef
5 changed files with 48 additions and 19 deletions

View File

@ -93,21 +93,23 @@ serve({
}
}
// Serve /build/* from frontend/build (compiled JS/CSS)
if (pathname.startsWith("/build/")) {
const assetPath = pathname.substring("/build/".length);
const filePath = path.join(frontendBuildDir, assetPath);
// Next.jsの静的ファイルを提供
if (pathname.startsWith("/_next/")) {
const assetPath = pathname.substring("/_next/".length);
const filePath = path.join(frontendBuildDir, "_next", assetPath);
try {
const file = Bun.file(filePath);
if (await file.exists()) {
let contentType = "application/octet-stream";
if (filePath.endsWith(".js")) contentType = "application/javascript; charset=utf-8";
else if (filePath.endsWith(".css")) contentType = "text/css; charset=utf-8";
else if (filePath.endsWith(".png")) contentType = "image/png";
else if (filePath.endsWith(".jpg") || filePath.endsWith(".jpeg")) contentType = "image/jpeg";
// 必要に応じて他のMIMEタイプを追加
return new Response(file, { headers: { "Content-Type": contentType } });
}
} catch (e) {
console.error(`Error serving file from frontend build dir ${filePath}:`, e);
console.error(`Error serving Next.js static file ${filePath}:`, e);
}
}