Skip to content

Commit 967ee99

Browse files
committed
書籍検索システム
1 parent 07fd705 commit 967ee99

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

docs/3-web-servers/05-form/_samples/book-search-system/main.mjs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,12 @@ app.get("/send", (request, response) => {
1616
const selectedBooks = books.filter(
1717
(book) => book.author === request.query.author,
1818
);
19-
response.send(`
20-
<!doctype html>
21-
<html lang="ja">
22-
<head>
23-
<meta charset="UTF-8" />
24-
<title>Document</title>
25-
</head>
26-
<body>
27-
<ul>
28-
${selectedBooks
29-
.map((selectedBook) => `<li>${selectedBook.title}</li>`)
30-
.join("")}
31-
</ul>
32-
</body>
33-
</html>
34-
`);
19+
const html_template = fs.readFileSync("./send.html");
20+
const html = html_template.replace(
21+
"{books}",
22+
selectedBooks.map((book) => `<li>${book.title}</li>`).join(""),
23+
);
24+
response.send(html);
3525
});
3626

3727
app.listen(3000);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
{books}
10+
</ul>
11+
</body>
12+
</html>

0 commit comments

Comments
 (0)