Skip to content

Commit 0458754

Browse files
committed
import fs -> import {readFileSync} と templateに統一
1 parent 8494994 commit 0458754

File tree

4 files changed

+16
-16
lines changed
  • docs/3-web-servers

4 files changed

+16
-16
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import express from "express";
2-
import fs from "fs";
2+
import { readFileSync } from "fs";
33

44
const app = express();
55

@@ -17,8 +17,8 @@ app.get("/send", (request, response) => {
1717
const selectedBooks = books.filter(
1818
(book) => book.author === request.query.author,
1919
);
20-
const html_template = fs.readFileSync("./send.html", "utf-8");
21-
const html = html_template.replace(
20+
const template = readFileSync("./send.html", "utf-8");
21+
const html = template.replace(
2222
"{books}",
2323
selectedBooks.map((book) => `<li>${book.title}</li>`).join(""),
2424
);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import express from "express";
2-
import fs from "fs";
2+
import { readFileSync } from "fs";
33

44
const app = express();
55

@@ -8,7 +8,7 @@ const messages = [];
88
app.use(express.urlencoded({ extended: true }));
99

1010
app.get("/", (request, response) => {
11-
const template = fs.readFileSync("index.html", "utf-8");
11+
const template = readFileSync("index.html", "utf-8");
1212
const html = template.replace(
1313
"{messages}",
1414
messages.map((msg) => `<li>${msg}</li>`).join(""),

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

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

55
const app = express();
66

@@ -12,8 +12,8 @@ app.get("/", async (request, response) => {
1212
const messages = await (
1313
await client.forum.findMany()
1414
).map((data) => data.message);
15-
const index = fs.readFileSync("index.html", "utf-8");
16-
const html = index.replace(
15+
const template = readFileSync("index.html", "utf-8");
16+
const html = template.replace(
1717
"{messages}",
1818
messages.map((msg) => `<li>${msg}</li>`).join(""),
1919
);

docs/3-web-servers/08-cookie/_samples/profile/main.mjs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import express from "express";
22
import cookieParser from "cookie-parser";
3-
import fs from "fs";
3+
import { readFileSync } from "fs";
44

55
const app = express();
66
app.use(express.urlencoded({ extended: true }));
@@ -10,14 +10,14 @@ import { PrismaClient } from "@prisma/client";
1010
const client = new PrismaClient();
1111

1212
app.get("/", (request, response) => {
13-
const index = fs.readFileSync("index.html", "utf-8");
13+
const index = readFileSync("index.html", "utf-8");
1414
const html = index.replace("{warning}", "");
1515
response.send(html);
1616
});
1717

1818
app.post("/login", async (request, response) => {
19-
const login = fs.readFileSync("login.html", "utf-8");
20-
const index = fs.readFileSync("index.html", "utf-8");
19+
const login = readFileSync("login.html", "utf-8");
20+
const index = readFileSync("index.html", "utf-8");
2121
const user = await client.User.findUnique({
2222
where: {
2323
username: request.body.username,
@@ -48,7 +48,7 @@ app.post("/login", async (request, response) => {
4848
});
4949

5050
app.get("/profile", async (request, response) => {
51-
const profile = fs.readFileSync("profile.html", "utf-8");
51+
const profile = readFileSync("profile.html", "utf-8");
5252
const prof = await client.Profile.findUnique({
5353
where: { id: request.cookies.session },
5454
});
@@ -60,14 +60,14 @@ app.get("/profile", async (request, response) => {
6060
});
6161

6262
app.get("/register", (request, response) => {
63-
const register = fs.readFileSync("register.html", "utf-8");
63+
const register = readFileSync("register.html", "utf-8");
6464
const html = register.replace("{warning}", "");
6565
response.send(html);
6666
});
6767

6868
app.post("/registered", async (request, response) => {
69-
const index = fs.readFileSync("index.html", "utf-8");
70-
const register = fs.readFileSync("register.html", "utf-8");
69+
const index = readFileSync("index.html", "utf-8");
70+
const register = readFileSync("register.html", "utf-8");
7171
const user = await client.User.findUnique({
7272
where: {
7373
username: request.body.username,

0 commit comments

Comments
 (0)