Skip to content

Commit 89a3b98

Browse files
authored
Merge pull request #8 from ut-code/local-assets
dev環境ではローカルのファイルを読むようにする
2 parents 0597dfa + 25790fc commit 89a3b98

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

app/[docs_id]/page.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { notFound } from "next/navigation";
22
import { ChatForm } from "./chatForm";
33
import { StyledMarkdown } from "./markdown";
44
import { getCloudflareContext } from "@opennextjs/cloudflare";
5+
import { readFile } from "node:fs/promises";
6+
import { join } from "node:path";
57

68
export default async function Page({
79
params,
@@ -12,10 +14,17 @@ export default async function Page({
1214

1315
let mdContent: string;
1416
try {
15-
const cfAssets = getCloudflareContext().env.ASSETS;
16-
mdContent = await cfAssets!
17-
.fetch(`https://assets.local/docs/${docs_id}.md`)
18-
.then((res) => res.text());
17+
if (process.env.NODE_ENV === 'development') {
18+
mdContent = await readFile(
19+
join(process.cwd(), "public", "docs", `${docs_id}.md`),
20+
"utf-8"
21+
);
22+
} else {
23+
const cfAssets = getCloudflareContext().env.ASSETS;
24+
mdContent = await cfAssets!
25+
.fetch(`https://assets.local/docs/${docs_id}.md`)
26+
.then((res) => res.text());
27+
}
1928
} catch (error) {
2029
console.error(error);
2130
notFound();

0 commit comments

Comments
 (0)