Skip to content

Commit eb90986

Browse files
authored
Merge pull request #527 from ut-code/fix-book-search-system-answer
Fix answer of book search system
2 parents 291cd32 + c458e12 commit eb90986

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import fs from "fs";
21
import express from "express";
3-
import ejs from "ejs";
42

53
const app = express();
64

@@ -18,9 +16,22 @@ app.get("/send", (request, response) => {
1816
const selectedBooks = books.filter(
1917
(book) => book.author === request.query.author,
2018
);
21-
const template = fs.readFileSync("template.ejs", "utf-8");
22-
const html = ejs.render(template, { selectedBooks: selectedBooks });
23-
response.send(html);
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+
`);
2435
});
2536

2637
app.listen(3000);

docs/3-web-servers/05-form/_samples/book-search-system/template.ejs

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)