Skip to content

Commit be8614c

Browse files
authored
Update answer of forum in form section (#658)
#657 ではデータベースの解答のみしか修正されていなかったため、他の解答も #657 に合わせました。
1 parent 48b5433 commit be8614c

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<!doctype html>
22
<html lang="ja">
33
<head>
4-
<meta charset="UTF-8" />
5-
<title>Document</title>
4+
<meta charset="utf-8" />
5+
<title>掲示板</title>
66
</head>
77
<body>
88
<ul>
99
<!-- messages -->
1010
</ul>
11-
<form action="/send" method="post">
12-
<input name="message" />
13-
<button>送信</button>
11+
<form method="post" action="/send">
12+
<input placeholder="メッセージ" name="message" />
13+
<button type="submit">送信</button>
1414
</form>
1515
</body>
1616
</html>
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
import express from "express";
21
import { readFileSync } from "node:fs";
2+
import express from "express";
33

44
const app = express();
5+
app.use(express.urlencoded({ extended: true }));
56

67
const messages = [];
78

8-
app.use(express.urlencoded({ extended: true }));
9-
9+
const template = readFileSync("./index.html", "utf-8");
1010
app.get("/", (request, response) => {
11-
const template = readFileSync("./index.html", "utf-8");
1211
const html = template.replace(
1312
"<!-- messages -->",
1413
messages.map((message) => `<li>${message}</li>`).join(""),
@@ -18,7 +17,7 @@ app.get("/", (request, response) => {
1817

1918
app.post("/send", (request, response) => {
2019
messages.push(request.body.message);
21-
response.send("送信しました。");
20+
response.redirect("/");
2221
});
2322

2423
app.listen(3000);

0 commit comments

Comments
 (0)