Skip to content

Commit 0b563dc

Browse files
committed
forum
1 parent 967ee99 commit 0b563dc

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed
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>Document</title>
6+
</head>
7+
<body>
8+
<ul>
9+
{messages}
10+
</ul>
11+
<form action="/send" method="post">
12+
<input name="message" />
13+
<button>送信</button>
14+
</form>
15+
</body>
16+
</html>

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

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,14 @@ const messages = [];
77
app.use(express.urlencoded({ extended: true }));
88

99
app.get("/", (request, response) => {
10-
response.send(`
11-
<!doctype html>
12-
<html lang="ja">
13-
<head>
14-
<meta charset="UTF-8" />
15-
<title>Document</title>
16-
</head>
17-
<body>
18-
<ul>
19-
${messages.map((message) => `<li>${message}</li>`).join("")}
20-
</ul>
21-
<form action="/send" method="post">
22-
<input name="message" />
23-
<button>送信</button>
24-
</form>
25-
</body>
26-
</html>
27-
`);
10+
const template = fs.readFileSync("index.html");
11+
const html = template.replace("{messages}", messages.map((msg) => `<li>${msg}</li>`).join(""));
12+
response.send(html);
2813
});
2914

3015
app.post("/send", (request, response) => {
3116
messages.push(request.body.message);
32-
response.send("送信しました");
17+
response.send("<body>送信しました</body>");
3318
});
3419

3520
app.listen(3000);

0 commit comments

Comments
 (0)