Skip to content

Commit 03c02fc

Browse files
committed
database + format
1 parent 36f7896 commit 03c02fc

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

docs/3-web-servers/06-get-post/_samples/forum/main.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ app.use(express.urlencoded({ extended: true }));
99

1010
app.get("/", (request, response) => {
1111
const template = fs.readFileSync("index.html");
12-
const html = template.replace("{messages}", messages.map((msg) => `<li>${msg}</li>`).join(""));
12+
const html = template.replace(
13+
"{messages}",
14+
messages.map((msg) => `<li>${msg}</li>`).join(""),
15+
);
1316
response.send(html);
1417
});
1518

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!doctype html>
2+
<html lang="ja">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Title</title>
6+
</head>
7+
<body>
8+
<ul>
9+
{messages}
10+
</ul>
11+
<form method="post" action="/send">
12+
<input placeholder="ここに入力してください。" name="message" />
13+
<button>送信</button>
14+
</form>
15+
</body>
16+
</html>

docs/3-web-servers/07-database/_samples/forum/main.mjs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import express from "express";
22
import { PrismaClient } from "@prisma/client";
3+
import fs from "node:fs";
34

45
const app = express();
56

@@ -11,24 +12,12 @@ app.get("/", async (request, response) => {
1112
const messages = await (
1213
await client.forum.findMany()
1314
).map((data) => data.message);
14-
response.send(`
15-
<!doctype html>
16-
<html lang="ja">
17-
<head>
18-
<meta charset="utf-8" />
19-
<title>Title</title>
20-
</head>
21-
<body>
22-
<ul>
23-
${messages.map((message) => `<li>${message}</li>`).join("")}
24-
</ul>
25-
<form method="post" action="/send">
26-
<input placeholder="ここに入力してください。" name="message" />
27-
<button>送信</button>
28-
</form>
29-
</body>
30-
</html>
31-
`);
15+
const index = fs.readFileSync("index.html");
16+
const html = index.replace(
17+
"{messages}",
18+
messages.map((msg) => `<li>${msg}</li>`).join(""),
19+
);
20+
response.send(html);
3221
});
3322

3423
app.post("/send", async (request, response) => {

0 commit comments

Comments
 (0)