feat: serve static assets from frontend build directory
This commit is contained in:
11
server.ts
11
server.ts
@ -62,11 +62,16 @@ app.post("/api/episodes/:id/regenerate", (c) => {
|
|||||||
// 静的ファイルの処理
|
// 静的ファイルの処理
|
||||||
|
|
||||||
// Vite ビルドの静的ファイル(main.js, assets/ など)
|
// Vite ビルドの静的ファイル(main.js, assets/ など)
|
||||||
app.get("/main.js", async (c) => {
|
app.get("/assets/*", async (c) => {
|
||||||
const filePath = path.join(frontendBuildDir, "main.js");
|
const filePath = path.join(frontendBuildDir, c.req.path);
|
||||||
const file = Bun.file(filePath);
|
const file = Bun.file(filePath);
|
||||||
if (await file.exists()) {
|
if (await file.exists()) {
|
||||||
return c.body(file, 200, { "Content-Type": "application/javascript; charset=utf-8" });
|
const contentType = filePath.endsWith(".js")
|
||||||
|
? "application/javascript"
|
||||||
|
: filePath.endsWith(".css")
|
||||||
|
? "text/css"
|
||||||
|
: "application/octet-stream";
|
||||||
|
return c.body(file, 200, { "Content-Type": contentType });
|
||||||
}
|
}
|
||||||
return c.notFound();
|
return c.notFound();
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user